Unity 2018 Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

How it works...

You have imported some cursor images, and set their Texture Type to Cursor, so they could be used to change the image for the user's mouse pointer. You also created a UI Button GameObject and added to it an Event Triggers component.

You added an instance of the CustomCursorPointer C# script class to the Button GameObject, and selected the magnifying-glass-style CursorZoom image.

You created a PointerEnter event, and linked it to invoke the OnMouseEnter method of the instance of the CustomCursorPointer script in the Button GameObject (which changes the mouse pointer image to the custom mouse cursor).

You created a PointerExit event, and linked it to invoke the OnMouseExit method of the instance of the CustomCursorPointer C# script class to the Button GameObject (which resets the mouse cursor back to the system default).

Essentially, you have redirected PointerEnter/Exit events to invoke the OnMouseEnter/Exit methods of the CustomCursorPointer C# script class so we can manage custom cursors for 2D, 3D, and UI GameObjects with the same scripting methods.