Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: vidjogamer on May 27, 2014, 04:45:48 PM

Title: Programatically set NGUI events.
Post by: vidjogamer 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?
Title: Re: Programatically set NGUI events.
Post by: Nicki 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.