Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: sean_microburst on May 06, 2014, 02:32:32 AM

Title: OnClick for a 'Set of Controls', not just 1 per button
Post by: sean_microburst on May 06, 2014, 02:32:32 AM
How can I create a Script than I can use for a "Set Of Controls".  I noticed that in OnClick you can get UICamera.currentTouchId.

Is there a way I can use that to create a 'Script' for a full Menu, instead of creating a script per button?

I am fairly new to NGUI, so this may just be a stupid question.

Thanks,
sean_microburst
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: ArenMook on May 06, 2014, 09:17:02 PM
On Click notification on the buttons can trigger any remote function, so I am not quite sure what you're asking here. Are you asking about the OnClick event? The actual event is sent to a single object by NGUI. Button handles that event and triggers the On Click Notification. The notification can call any remote function, or even several functions as you see fit.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: daybson on May 23, 2014, 03:12:04 PM
Same doubt here.

I have a window with several buttons.
I don't want to put one script in each button to implement his OnClick event.

What I want is to put ONE script at my Window (on top of hierarchy, with childrens buttons) and my buttons will doesn't have none script attached. At the Window script, I want to check which button was clicked and activate an method at my way.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: ArenMook on May 23, 2014, 05:31:08 PM
You don't need to attach any scripts to use the built-in On Click notification on the UIButton.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: daybson on May 23, 2014, 07:11:52 PM
Well, I'm missing something then.
Can you explain me how do I do this? Several buttons activating different functions without any script attached to they?
Or in my case, only one script in my window?
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: ArenMook on May 23, 2014, 09:33:56 PM
Select your button and examine the UIButton component. Do you see the On Click notification? Drag in your game object that has the script whos method you want to call. Now choose that method in the drop-down list.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: daybson on May 26, 2014, 07:46:25 AM
Drag in your game object that has the script whos method you want to call. Now choose that method in the drop-down list.

I did not understand. Drag the method? Drag what to where? I'm using the 2.6.4 version, and I did not see this 'OnClick notification'.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: Cripple on May 26, 2014, 08:05:45 AM
lol,

The version that you use is 1 year old ... you should upgrad your NGUI to the last version, but be careful ... ngui has been reworked since the 3.X.X version, you will have to migrate your work.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: daybson on May 26, 2014, 08:10:34 AM
I can not migrate without rewrite some classes at my project, and this will be very traumatic. For my needs, this version still works (I hope). I'm waiting to Unity 4.6 with the new GUI system, to analyse if will worth migrate to it.
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: devandart on May 26, 2014, 08:22:05 AM
But what's easier?
Hacking around in a old NGUI version or migrating the latest version? Hm...
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: daybson on May 26, 2014, 08:33:16 AM
For now, it's easier usgin the old version. I have no time to migrate.  =/
Title: Re: OnClick for a 'Set of Controls', not just 1 per button
Post by: daybson on May 26, 2014, 12:55:57 PM
Well, it's solved!  ;)

I Added a UICheckbox script to the button.
I created a ComponentManager script and I have attached it to a empty gameobject. This script contains the functions that I need to each button of my window. I used it as the the Eventreceiver on UICheckBoxand of a button and wrote the name of my desired method (implemented on my manager) for this button in the FunctionName field.