In this video we are going to see how to change the cursor image in Unity when we pass the pointer over a button.
🎁 DOWNLOAD THE UNITY PACKAGE HERE:
https://gamedevtraum.com/en/game-and-...
We start by configuring the default cursor sprite by going to Edit - Project Settings, there we can assign the default cursor sprite, as well as its hotspot coordinates. The hotspot is an offset vector measured from the top left corner of the Sprite to the point where the cursor tip is considered to be.
The script that comes in the package has fields defined to assign the Sprite of two cursors as well as the vectors of their respective hotspots. TTo determine the Hotspots you have to enter the game mode and try different values until the cursor matches, another way would be to know exactly how many pixels horizontally and vertically is the point of the cursor.
In this particular case we are interested in constantly displaying a default cursor until the mouse cursor hovers over a button. Then we have to be able to detect exactly when these events occur and for that we assign to each button an "Event Trigger" component, defining the "Pointer Enter" and "Pointer Exit" events. To both events we assign the GameObject that has the Script with the functions we want to execute (these functions must be defined as public) and then using the drop-down menu we choose the functions to execute in each event.
____________________________________________________________
LINKS
Portfolio: https://gamedevtraum.com/en/portfolio...
LinkedIn: / gamedevtraum
Downloads: https://gamedevtraum.itch.io/
Contact 1: [email protected]
Contact 2: / gamedevtraum
____________________________________________________________