Author Topic: UIEventListener extra parameter  (Read 2508 times)

hvilela

  • Guest
UIEventListener extra parameter
« on: October 02, 2012, 04:07:33 PM »
I'm creating a few buttons with a for, and adding colliders and event listeners to each one. All this buttons call the same function when OnClick is dispatched.
I can receive the button itself as parameter in the called function, but I would like to receive the button index.

Is it possible to pass a second parameter to it, to any other workaround?
« Last Edit: October 02, 2012, 04:39:41 PM by hvilela »

PapaWhiskey

  • Guest
Re: UIEventListener extra parameter
« Reply #1 on: January 11, 2013, 08:39:13 AM »
i added a variable "userData" to UIButtonColor (the parent of UIButton) and in the callback I do a getComponent<UIButton> and then query the userData variable...would like to make that variable generic, but for my purposes I only needed an int button index

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIEventListener extra parameter
« Reply #2 on: January 11, 2013, 01:27:00 PM »
For anything that requires a parameter, create a custom script instead of using UIEventListener. Attach this custom script to your buttons, and implement the OnClick function.

PapaWhiskey

  • Guest
Re: UIEventListener extra parameter
« Reply #3 on: January 11, 2013, 06:35:57 PM »
well he said he wanted to know the index of the buttons he was creating and they all call the same onClick routine...you either figure out which button via name or you do something like i did and extend the button class to have a generic userData variable...when you create the buttons in code (as he indicated he is), its much easier to just set the userData variable to the index of the for loop, and then when onClick is called (or whatever function you add to the UIEventListener queue) you can then query what the userData value is...