Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Creating custom cursors

From: Unity 3D 3.5 Essential Training

Video: Creating custom cursors

Between levels and GUI we've now covered enough to be able to make a start menu. So I've gone ahead and made a simple one for us to use. Let's import the StartMenu package, right-click > Import Package > Custom Package and 13-07 > Assets, and we're going to select StartScreen, click Open and Import. This one adds a new scene directly to our scenes folder.

Creating custom cursors

Between levels and GUI we've now covered enough to be able to make a start menu. So I've gone ahead and made a simple one for us to use. Let's import the StartMenu package, right-click > Import Package > Custom Package and 13-07 > Assets, and we're going to select StartScreen, click Open and Import. This one adds a new scene directly to our scenes folder.

Let's go ahead and double- click on it to load it. And we're looking for StartMenu, and we can save the scene. As you've probably guessed, the start screen exists only in scripting. Let's go ahead and select the main camera where our script resides and then open our StartScreen script. The main thing of interest here is the use of backslash N in the text string for instructions.

It gives us an easy way to control the line feeds without adding more controls. We're also using GUI.DrawTexture. We'll see GUI.DrawTexture in another video. With the introduction of Unity GUI, it's no longer feasible to use GUI texture objects as cursors. Unity GUI controls are always drawn on top of everything else. So to make a custom cursor, we're going to need to use the Unity GUI. We'll do that in the StartScreen script.

First we'll need to tell it what texture to use, so let's create a variable, var pointer of type texture. Give myself a little bit of room and var pointer of type Texture. Next we're going to need a start function to make sure we can turn the operating system cursor off. I'm going to get that one from the snippets file, Exercise Files13/13-07/Snippets.

And I'll just copy the entire start function here, right-click, Copy, and I'm going to put it right below the variable declarations. So that's going to turn our screen cursor off. Now we'll need to know where the operating system cursor's position is. To do that we're going to use Event.current.mousePosition. Let's test it first. Let's go ahead and get the code from Snippets again. And this is the one we want.

We're going to test it with a print statement first, right-click and Copy. And let's go ahead and add it at the bottom of the OnGUI function, Ctrl+V to Paste, let's save this script now and head back to the editor. Let's start by turning on Maximize on Play, and then we can go ahead and click Play and move the mouse around. It's position will be reported in the console. Let's turn on Maximize on Play, and also, let's change from Free Aspect to our Standalone size, 1024x768.

Now we can click Play, and here is our little splash screen. It's a little bit off because we aren't a full 1024x768 yet, but we can get the idea. Let's move our cursor around. In the bottom left you can see that the position is being reported in the console, and let's exit Play mode. So now, let's convert that position to a variable that we can get the X and Y from. I'll get that code from Snippets as well. And we're going to get these two lines, right-click and Copy, back to the Script editor, and we're going to put them below our print line and comment out our print line.

Now we can get the X and Y position using mousePos.x and mousePos.y that we get from this variable we've added here. So let's save our script and head back to the editor, and we need to find a texture for our pointer. Let's select the Textures folder, right- click and Import New Asset, and here we have GamePointerSm, and that's the one we want. Select it and Import.

It's a little different than the operating cursor system. Let's select the Main Camera now and drag our new GamePointerSm onto the pointer field, and let's click Play. Now we have a custom cursor, and let's exit Play mode. We're going to try one more thing here. Let's change the color of our cursor. To change the color of a GUI control, we need to use GUI.color.

Every control after that line will inherit the color. So if we needed to clear the color, we would use GUI.color = color.white after the colored control. Let's go back to the Script editor and add a variable for our color. So up at the top I'm going to add var cursorColor of type color, and we'll go ahead and initialize it to Color.green, and in the on GUI function above the mouse pointer code, we're going to add GUI.color = cursorColor.

Let's save our script and head back to the editor. And now we can see our new variable. It's a color swatch. Maybe green isn't going to be the best choice, so I'm going to go ahead and click on it now, and I want to change mine to kind of a reddish-orange. Let's click Play and test the new cursor. And there it is, our newly-colored cursor. Let's exit Play mode and then save the scene, so we can add it to the build.

File > Save Scene, and now we're going to use Build Settings. Add Current, and this one needs to be at the top, so we'll just drag it up and drop it, and we'll click Build. Let's just use the same file and save, and yes we want replace it. And we'll close that window, then we'll the close Build Settings window. And finally, remember the crosshair we turned off a while back? We can now replace it with a simple script with the GUI control.

Let's go ahead and get back to the main level for a minute. Double-click to open the main level, we're going to use Import New Asset to bring in the GUI's crosshair script, and we want to bring it into the game scripts folder, so I'm going to select that, right-click > Import New Asset, going to go out to my Desktop, Exercise Files13/13-07/Assets, and here's the script we want, select it and Import.

Now we can open up the first-person controller and the Main Camera and the Weapon Handler and drop our script on the Proxy Weapon. Since this script is a child of the object, it gets deactivated when the object does, so there's only one thing we need to do now, and that is select the Proxy Weapon and assign the crosshair texture. And here it is right here, and we'll drag and drop it into the crosshair field.

I'm going to turn off Maximize on Play, click Play, and I'm going to turn towards a darker area, and now when I press 0 on my keypad, our crosshair comes and goes with the Proxy Weapon, and let's exit Play mode. I'll press Escape and exit. With the addition of a start screen, we should be in good shape to play through our game.

Show transcript

This video is part of

Image for Unity 3D 3.5 Essential Training
Unity 3D 3.5 Essential Training

106 video lessons · 21155 viewers

Sue Blackman
Author

 
Expand all | Collapse all
  1. 3m 36s
    1. Welcome
      59s
    2. Unity basics
      1m 8s
    3. Using the exercise files
      1m 29s
  2. 34m 40s
    1. Exploring the interface
      4m 28s
    2. Organizing your project
      8m 12s
    3. Exploring Scene view
      3m 14s
    4. Navigating Scene view
      2m 52s
    5. Creating objects
      7m 38s
    6. Transforming objects
      8m 16s
  3. 32m 45s
    1. Setting up the terrain geometry
      4m 19s
    2. Painting the topography
      3m 56s
    3. Painting the terrain textures
      7m 9s
    4. Painting trees and forests
      4m 56s
    5. Painting grass, shrubs, and 3D geometry
      3m 58s
    6. Painting detail meshes
      5m 4s
    7. Adjusting terrain settings
      3m 23s
  4. 24m 18s
    1. Adding sun, sky, and fog
      6m 0s
    2. Using the First Person Controller
      4m 31s
    3. Publishing project settings
      3m 37s
    4. Introducing the game environment
      4m 33s
    5. Fine-tuning the First Person Controller
      5m 37s
  5. 1h 14m
    1. Exploring Unity scripting
      3m 34s
    2. Using variables
      11m 46s
    3. Discovering functions
      4m 10s
    4. Using syntax, punctuation, and the console
      5m 39s
    5. Looking at function syntax
      3m 44s
    6. Printing to the console
      8m 28s
    7. Exploring rotation and time functions
      8m 22s
    8. Scripting basic functions
      7m 12s
    9. Combining transforms
      5m 27s
    10. Setting transforms
      8m 34s
    11. Using conditionals to create gameplay
      7m 49s
  6. 1h 15m
    1. Exploring distance and local variables
      8m 43s
    2. Raycasting
      6m 56s
    3. Building timers
      7m 8s
    4. Creating a simple projectile
      13m 16s
    5. Refining the projectile
      5m 32s
    6. Exploring the OnCollision variable and tags
      10m 20s
    7. Sending messages
      3m 38s
    8. Reacting to messages
      4m 50s
    9. Juggling Play and Edit modes
      7m 33s
    10. Suppressing input
      8m 2s
  7. 1h 10m
    1. Creating GameObjects
      6m 14s
    2. Understanding components
      5m 3s
    3. Using colliders for barriers
      7m 15s
    4. Using colliders for triggers
      4m 28s
    5. Exploring physics
      7m 15s
    6. Working with physics components
      4m 39s
    7. Making cloth
      9m 56s
    8. Working with wind zones
      7m 50s
    9. Using an audio source
      6m 14s
    10. Creating a sound zone
      5m 34s
    11. Adding audio effects
      6m 31s
  8. 52m 25s
    1. Creating and reusing prefabs
      8m 11s
    2. Using prefabs with arrays
      5m 28s
    3. Introducing randomness
      5m 0s
    4. Creating particle systems
      6m 58s
    5. Refining particle systems
      5m 30s
    6. Combining particle systems
      7m 10s
    7. Upgrading weapons
      6m 15s
    8. Exploring water effects
      7m 53s
  9. 48m 33s
    1. Importing static objects
      12m 36s
    2. Manipulating textures
      5m 42s
    3. Working with materials and shaders
      5m 17s
    4. Handling multiple materials
      5m 42s
    5. Animating UVs
      8m 27s
    6. Tracking objects with LookAt
      5m 45s
    7. Using Linecast and the Line Renderer
      5m 4s
  10. 53m 42s
    1. Investigating ambient light
      2m 21s
    2. Looking at light types
      3m 13s
    3. Exploring shadows
      5m 23s
    4. Baking lighting with Beast
      8m 16s
    5. Experimenting with Beast
      7m 42s
    6. Baking the game scene
      4m 20s
    7. Creating lighting effects
      6m 24s
    8. Adding a flashlight
      9m 20s
    9. Exploring waypoints and death zones
      6m 43s
  11. 49m 15s
    1. Platformer setup: Snaps and cosines
      8m 42s
    2. Using the Animation view
      9m 53s
    3. Working with multiple animation clips
      5m 40s
    4. Triggering keyframe animations
      5m 58s
    5. Animating transparency
      7m 7s
    6. Keyframing events
      6m 28s
    7. Avoiding keyframing pitfalls
      5m 27s
  12. 36m 55s
    1. Importing skinned meshes
      9m 42s
    2. Adding to imported animations
      3m 23s
    3. Dynamic parenting
      6m 44s
    4. Exploring character controllers
      5m 10s
    5. Importing an animated character
      6m 2s
    6. Activating the character animation
      5m 54s
  13. 30m 18s
    1. Introducing cameras
      4m 53s
    2. Working with cameras and layers
      4m 44s
    3. Activating the platformer scene
      7m 27s
    4. Adding obstacles and pushing physics
      5m 40s
    5. Managing multiple levels
      7m 34s
  14. 43m 14s
    1. Working with the Unity GUI
      10m 31s
    2. Using GUI skins
      6m 30s
    3. Exploring controls
      3m 0s
    4. Introducing fonts and styles
      5m 27s
    5. Scripting in-game menus
      3m 44s
    6. Hooking up an in-game menu
      5m 20s
    7. Creating custom cursors
      8m 42s
  15. 18m 59s
    1. Creating fade transitions
      5m 34s
    2. Setting AI pathfinding
      9m 56s
    3. Using render textures for spy cams
      3m 29s
  16. 1m 13s
    1. What's next
      1m 13s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Unity 3D 3.5 Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.