Author Topic: One Click to Rule Them All!!  (Read 1396 times)

jaz1974

  • Guest
One Click to Rule Them All!!
« on: December 05, 2013, 07:44:03 PM »
Hi guys,

I'm hoping for some guidance.

I have a set of buttons which do something when clicked (using an OnClick script).
I'm trying to figure out how I can click all those buttons simultaneously by clicking on a single master button.

Looking into it, it seems I should be using UIEventListener, but I'm struggling with how I should set this up.
Anyone got any advice?

Much appreciated,

Jaz


Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: One Click to Rule Them All!!
« Reply #1 on: December 06, 2013, 03:54:50 AM »
Depends on what you mean by Click.

If you want to make a full fake clicking, then you can forward the OnClick event from your master button to the others.

  1. //Masterbutton script
  2. public GameObject[] slaveButtons;
  3.  
  4. void OnClick()
  5. {
  6. foreach(var b in slaveButtons)
  7. b.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
  8. }

Or the slavebuttons can subscribe to the master button's events as well

  1. //slave button script
  2. public GameObject masterButton;
  3. Start()
  4. {
  5. UIEventListener.Get(masterButton).onClick += SlaveOnClickHandler;
  6. }
  7. void SlaveOnClickHandler()
  8. {//...
  9. }
  10.  

jaz1974

  • Guest
Re: One Click to Rule Them All!!
« Reply #2 on: December 06, 2013, 05:06:24 AM »
Thanks for the info Niki,

Any chance you could elaborate on the Masterbutton script?

I'm not sure how I identify the slaveButtons here?  I.e. how do I make sure the OnClick message only gets sent to the relevant objects?

Many thanks,

Jaz