How to do it...

To set a custom mouse pointer when the mouse moves over a UI control GameObject, do the following:

  1. Create a new Unity 2D project.
  2. Import the provided IconsCursors folder. Select all three images in the Project panel, and in the Inspector change the Texture Type to Cursor. This will allow us to use these images as mouse cursors without any errors occurring.
  3. Import the provided _Scripts folder, containing the CustomCursorPointer C# script class.
  4. Add a UI Button GameObject to the scene, leaving this named as Button.
  1. Add an instance of the CustomCursorPointer C# script class to the Button GameObject.
  2. With the Button GameObject selected in the Hierarchy, drag the CursorZoom image into the public Cursor Texture 2D variable slot ...

Get Unity 2018 Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.