Author Topic: Programatically set NGUI events.  (Read 3154 times)

vidjogamer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Programatically set NGUI events.
« on: May 27, 2014, 04:45:48 PM »
Hello, I want to instantiate a some of your built in prefabs like the simple control button, then set its on click to a function of my choice. How does one do this via code?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Programatically set NGUI events.
« Reply #1 on: May 28, 2014, 04:04:04 AM »
UIButton has a public list of EventDelegates

  1. public List<EventDelegate> onClick = new List<EventDelegate>();

that can hook up to.

  1. UIButton myButton;
  2. void Start(){
  3. EventDelegate.Add(myButton.onClick, MyMethod);
  4. }
  5.  
  6. void MyMethod(){
  7. Debug.Log("My button was clicked!");
  8. }
  9.