Setting custom mouse cursors for UI controls
The previous recipe demonstrated how to change the mouse pointer for 2D and 3D GameObjects receiving OnMouseEnter
and OnMouseExit
events. Unity UI controls do not receive OnMouseEnter
and OnMouseExit
events. Instead, UI controls can be made to respond to PointerEnter
and PointerExit
events if we add a specialEvent Trigger component to the UI GameObject. In this recipe, we'll change the mouse pointer to a custom magnifying glass cursor when it moves over a UI Button GameObject:

Getting ready
For this recipe, we'll use the same asset files as for the previous recipe, and its CustomCursorPointer
C# script class, all of which can be found in the02_07
folder.
How to do it...
To set a custom mouse pointer when the mouse moves over a UI control GameObject, do the following:
- Create a new Unity 2D project.
- Import the provided
IconsCursors
folder. Select all three images in theProjectpanel, and in theInspectorchange theTexture TypetoCursor. This will allow us...