Author Topic: best way to call method from tab buttons  (Read 1726 times)

travisschau

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
best way to call method from tab buttons
« on: October 18, 2013, 07:16:35 PM »
Hi,

I'm creating about 8 tabs, and attaching the UIToggle script to each one. That part is great, but I'm not sure what the best way is to trigger script methods from them.

My instinct would have been to have all my tabs call the same method on value change ("onTabClick"), and then somehow check which tab made the call and perform the appropriate action. I don't see any way to do that, since I can't pass the tab GameObject as a parameter or anything.

Alternately, I could actually create 8 methods in my script, but then updating my tab prefab would reset which method they all call in the editor and force me to set each tab to the corresponding 8 methods each time I change the prefab.

Not sure if this makes total sense, but any advice on triggering actions from tabs or groups of buttons without creating a whole bunch of methods or having to do a lot of Unity Editor legwork would be appreciated!

Thanks, and I'm a big NGUI fan btw!
-Travis

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: best way to call method from tab buttons
« Reply #1 on: October 18, 2013, 07:18:40 PM »
UIToggle.current tells you what toggle called the method. UIToggle.current.value tells you the state (true or false).

travisschau

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: best way to call method from tab buttons
« Reply #2 on: October 18, 2013, 07:44:50 PM »
Thanks so much!! I knew there was a better answer.