Author Topic: Prebaf button losing target.  (Read 2589 times)

Balours

  • Guest
Prebaf button losing target.
« 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 :)

npritchard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Prebaf button losing target.
« Reply #1 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

Balours

  • Guest
Re: Prebaf button losing target.
« Reply #2 on: November 28, 2013, 10:28:30 AM »
Thank you, worked perfectly.

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