Author Topic: How do you reference buttons in code?  (Read 1358 times)

Boomer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
How do you reference buttons in code?
« on: June 30, 2014, 12:36:51 AM »
As per the title suggests, I've Googled this issue but cannot, for the life of me, figure out how to make references to my NGUI buttons in code.

For a little more information, I'm trying to make a GUI where when you click a button it pops up another button created with NGUI.  In order to do this I need to use Show and Hide commands within C#.  This, however, is proving difficult due to my inability to set calls to the buttons within the code itself.  I might be missing something simple, I suppose (very new to Unity.) 

Any assistance, or pointing towards something where I can help myself would be greatly appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do you reference buttons in code?
« Reply #1 on: July 01, 2014, 02:58:12 AM »
Via code?
  1. UIEventListener.Get(buttonGameObject).onClick = YourCallback;
...or using the button component's on click notification (same as you see in inspector):
  1. EventDelegate.Set(GetComponent<UIButton>().onClick, YourCallback);