- Home /
NGUI Buttons
Hello,
I'm brand new to Unity and I'm trying to figure out how to use NGUI to make menus for my game. The documentation says there's an onClick() function for each button but I can't find it. How do I execute code when my buttons are clicked?
Answer by fffMalzbier · Jan 24, 2013 at 06:17 PM
Just create a function in the script that is attached to the button Game object. For example like this:
void OnClick ()
{
//Do stuff
}
That function will be called every time the button is pressed.
Where can I find the script that's attached to the button?
You just need to write up your own script and attach it to the required button which has the collider. On that script, just use the OnClick () function. That's it.
Answer by Geo.Ego · Aug 13, 2013 at 08:56 PM
I wrote up a tutorial that just covers making a button in NGUI from scratch. As fffMalzbier said, you basically just need a script that does something in the OnClick () method, and the code inside is executed every time the button gets clicked.
Hello Geo.Ego. I saw your tutorial and this is great. Could you tell me way to hide this button after click/press it? Thanks