Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: alenb on July 17, 2012, 08:20:09 PM

Title: How to check if Button is clicked from main script?
Post by: alenb on July 17, 2012, 08:20:09 PM
Hi All,

Instead of having individual scripts for each NGUI Button I would like to simply reference the button from my main script and check if it has been clicked. Is such a thing possible? I've been banging my head against the table for a day and a half and I cannot for the life of me find any option that allows me to do such a thing.

Please if anyone has any ideas let me know.


Thank you =)
Title: Re: How to check if Button is clicked from main script?
Post by: ArenMook on July 17, 2012, 10:27:00 PM
Of course. Use the UIEventListener.Get(buttonGameObject).onClick += YourClickCallback;
Title: Re: How to check if Button is clicked from main script?
Post by: alenb on July 17, 2012, 10:58:57 PM
Thank you so much for your reply. It's all working now =)
Title: Re: How to check if Button is clicked from main script?
Post by: lbzzbl on July 18, 2012, 09:49:12 AM
in this case, which is the preferable usage or gives better performance?

UIEventListener.Get(buttonGameObject).onClick += YourClickCallBack

or

setting the button to have a UIButtonMessage script and call YourClickCallBack?
Title: Re: How to check if Button is clicked from main script?
Post by: PhilipC on July 18, 2012, 10:38:08 AM
From a performance standpoint

UIEventListener.Get(buttonGameObject).onClick += YourClickCallBack

is faster and UIButtonMessage uses SendMessage which is slower then directly calling the function.
Title: Re: How to check if Button is clicked from main script?
Post by: lbzzbl on July 18, 2012, 12:21:10 PM
thanks a lot.

looks like it is time to change the code... :)
Title: Re: How to check if Button is clicked from main script?
Post by: PhilipC on July 18, 2012, 02:03:01 PM
If you've done it the other way i would say leave it unless your really looking for something to do. Its not THAT much worse...