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

How it works...

You created a Sprite GameObject and assigned it the Unity logo image. You 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 added a Box Collider to the sprite GameObject so that it would receive OnMouseEnter and OnMouseExit event messages.

You created the CustomCursorPointer script class, and added an instance-object of this class to the sprite GameObject – this script tells Unity to change the mouse pointer when an OnMouseEnter message is received, that is, when the user's mouse pointer moves over the part of the screen where the Unity logo sprite image is being rendered. When an OnMouseExit event is received (the users mouse pointer is no longer over the cube part of the screen), the system is told to go back to the operating system's default cursor. This event should be received within a few milliseconds of the user's mouse exiting from the collider.

Finally, you selected the image CursorTarget to be the custom mouse-pointer cursor image the user sees when the mouse is over the Unity logo image.