Events methods
When using C# with NGUI, there are some methods that you will regularly use when you need to know if your object is currently hovered upon, pressed, or clicked.
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. Thestate
bool gives the hover state; ifstate
istrue
, the cursor just entered the object's collider. Ifstate
isfalse
, the cursor has just left the collider's bounds.OnPress(bool state)
: This method works in the exact same way as the previousOnHover()
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 theUICamera.currentTouchID
variable; 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...