Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Balours on November 28, 2013, 10:14:44 AM

Title: Prebaf button losing target.
Post by: Balours on November 28, 2013, 10:14:44 AM
Hi,

Thanks for this plugin !

I'm stuck on creating button prefab at runtime, the notified gameObjet is outside the prefab so the link is removed by unity.

How can I add the notify and the function to call at runtime, just after creating the button ?

Thanks !

Balours :)
Title: Re: Prebaf button losing target.
Post by: npritchard on November 28, 2013, 10:22:58 AM
Hook into the onClick event...
  1. void CreateButton() {
  2.   UIButton createdBtn = ;// code to create and get the UIButton component
  3.   EventDelegate.Add(createdBtn.onClick, OnCreatedButtonClick);
  4. }
  5.  
  6. void OnCreatedButtonClick() {
  7.   Debug.Log("Button Pressed");
  8. }

Don't forget to EventDelegate.Remove(...) when appropriate.

HTH
Title: Re: Prebaf button losing target.
Post by: Balours on November 28, 2013, 10:28:30 AM
Thank you, worked perfectly.

I had no idea of how EventDelegate worked. Now I got it.