Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 0 down vote accepted

Yup.

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.