Skip to content

Changing Mouse Pointers

Sean Oldfield edited this page Oct 15, 2018 · 1 revision

Changing Mouse Pointers

To provide better feedback to users, game objects can be customized so that the cursor changes when it, for example, hovers over a game object.

Setup

In order to use custom mouse pointers in your scene, you need both a single CursorHandler, and many CursorStyler's.

Cursor Handler

The Cursor Handler is a script located in Assets/Scripts/UserInterface/CursorHandler.cs.

The handler is used by all CursorStyler instances to change the cursor accordingly. To configure the CursorHandler in your scene, add the script to your Main Camera game object and ensure it has the tag MainCamera.

Set the properties of the handler accordingly: (NOTE: Cursor Textures are just sprites that have their Texture Type set as Cursor)

  • Mouse Default Texture: This is the default mouse icon that will be used during the game when it is not hovering over anything.
  • Mouse Over Texture: This is the mouse icon when the mouse is hovering over a component with the CursorStyler script.
  • Mouse Drag Texture: This is the mouse icon used when the CursorStyler component is being dragged.
  • Cursor Mode: Unity Documentation
  • Hotspots: The hotspots are the offsets between the cursor image and the click box of the cursor. For example, if your default cursor icon has its point located away from the corner of the actual image, use the offsets to line up the mouse box corner and the image corner.

NOTE: There is default mouse icons found in Assets/Sprites/ui/cursors/ and their configurations for the CursorHandler are as follows:

Cursor Styler

With the CursorHandler configured, getting the cursors to change is as simple as adding a CursorStyler script to every Game Object you wish to be able to change the cursor type, e.g. Buttons, Draggable Blocks etc.

Clone this wiki locally