Author Topic: Button with arguments  (Read 2190 times)

Tama

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Button with arguments
« on: July 04, 2014, 09:27:47 AM »
I'm trying to make a set of buttons that call the same function but with a different argument value. I saw that back in 2012, someone had the same problem here:
http://www.tasharen.com/forum/index.php?topic=2353.0
and never solved it. I can see that if I add a button and put in a method that takes parameters, the button inspector shows an "Arg 0" field, but that seems to want me to drag in a gameobject. I want to be able to pass a string or int, for instance, not a gameobject.

I know I can make different methods that just differ in what value they pass on, and then attach each button to one of these methods, but I was wondering if there was a neater solution?

schneidb

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 2
  • Posts: 24
    • View Profile
Re: Button with arguments
« Reply #1 on: July 04, 2014, 12:26:20 PM »
There are a couple of options (neither of which give you exactly what you want, but might be of use to you)...

One approach in this thread: http://www.tasharen.com/forum/index.php?topic=10206.msg47892#msg47892

Another is to not pass a parameter at all, but use UIButton.current to identify which button was pressed and then do your branching based on that.