If you attach a script to any object with a collider on it (for example, a button or a 3D object), you can add the following useful methods in the script to catch events:
OnHover(bool state): This method is called when the object is hovered or unhovered. The
statebool gives the hover state; if
true, the cursor just entered the object's collider. If
false, the cursor has just left the collider's bounds.
OnPress(bool state): This method works in the exact same way as the previous
OnHover()method, except it is called when the object is pressed. It works with a touch or click. If you need to know which mouse button was used to press the object, use the
UICamera.currentTouchIDvariable; if this int is equal to -1, it's a left-click. If it's equal to -2, it's a right-click. Finally, if it's equal to -3...