Author Topic: Passing the button object to the OnClick method?  (Read 2664 times)

bodosaher

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Passing the button object to the OnClick method?
« on: May 10, 2014, 08:11:34 AM »
In previous NGUI versions I used to have a master script and when a button gets clicked it sends OnClick message to the script, I used something like this:
public void ButtonClicked(Gameobject g) {}
That used to work to determine which button got clicked but now with the new NGUI I cant use those parameters and instead I have to leave the parameters field empty "public void ButtonClicked() {}"
If I use the previous technique I get the error ArgumentException: Couldn't bind to method 'ButtonPressed'.
Any solutions?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Passing the button object to the OnClick method?
« Reply #1 on: May 11, 2014, 12:26:55 AM »
On Click notification set on the UIButton in inspector lets you choose any function, including functions that have parameters. If you choose a function with parameters, you can then set those parameters using any value you want, including passing the button's game object if you like.

However UIButton.current.gameObject already tells you that.