When scripting in C# with the NGUI plugin, some methods will often be used. For example, you will regularly need to know if an object is currently hovered upon, pressed, or clicked. Of course, you could code your own system—but NGUI handles that very well, and it's important to use it at its full potential in order to gain development time.
When you create and attach a script to an object that has a collider on it (for example, a button or a 3D object), you can add the following useful methods within 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 also works for touch-enabled devices. If you...