Author Topic: Add EventDelegate on UIButton script Runtime .  (Read 3332 times)

Arun

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 1
    • View Profile
Add EventDelegate on UIButton script Runtime .
« on: November 05, 2014, 12:00:46 AM »
Hi guys ,

 I am trying to add EventDelegate (OnClick) on UIButton script Runtime .This Script is attached to a Button prefab .I am trying to add CloseButton() Method of same mono behaviour from where i am creating this prefab. Cross Button is a child of portPrefab .
  1. portPrefab = Instantiate (portDashboard, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
  2. GameObject.Find ("Cross Button").GetComponent<UIButton> ().onClick.Add (new  EventDelegate (this, "CloseButton"));

I can't see it added in inspector .

Update :
I can also see delegate is added in the list(onClick) , but it's not executing .Is it even feasible to add EventDelegate at runtime and expect them to run properly . When i try to add them via Inspector in prefab . It removes itself when prefab is instantiated at runtime .
« Last Edit: November 05, 2014, 12:40:53 AM by Arun »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Add EventDelegate on UIButton script Runtime .
« Reply #1 on: November 06, 2014, 01:25:22 AM »