Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I feel like Im missing something really simple, but Ive read about all the events NGUI can generate from an object and just dont get where to recive (or handle) the event. Do I just attach it to a script on the object?

share|improve this question
up vote 0 down vote accepted


You can also look into add-on frameworks like NData, which is a MVVM data manager which can simplify a lot of UI code (and complicate other UI code; use the right tool for the job and all that jazz).

share|improve this answer
Im using the free version of ngui for the moment, so I probably wont invest in Ndata just yet. So on my object I just add a script with something like self.onClick = myFunction or is that wrong? All of the NGUI examples just seem to be using other NGUI functions and scripts. My main issue is how to I tie the UI to my game – ProtoJazz Nov 13 '12 at 20:47
I finaly get it. I knew it would be something so simple but I just couldnt figure it out. For anyone else who has no idea what they are doing, it really is just as easy as adding a script to your object For mine I was using Java Script, so my object has a script with function OnClick(){ Application.LoadLevel("main");} – ProtoJazz Nov 15 '12 at 16:44

The easiest way to handle UI Events in NGUI is to use the UIEventListener class. All you have to do is call it like this:

UIEventListener.Get(buttonObj).onClick += YourClickCallback;
share|improve this answer

Some of the NGUI widget scripts have delegates to handle events, I just modified the rest to let me supply event handlers - ie. added a buttonClickDelegate and buttonHoldDelegate to UIButton

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.