Search Unity

How can i add persistent listeners to a Button.onClick

Discussion in 'UGUI & TextMesh Pro' started by xShadoWalkeR, Apr 23, 2019.

  1. xShadoWalkeR

    xShadoWalkeR

    Joined:
    Apr 26, 2018
    Posts:
    1
    So what i'm doing is spawning a new button for a dialogue system i'm working on. And when i spawn that button i was to add an OnClick event to do what i wan't so basically i wan't to go from this:

    upload_2019-4-23_21-19-19.png

    To this:
    upload_2019-4-23_21-25-40.png

    This is the code i have at the moment:
    Code (csharp):
    1.  
    2. Button temp = buttons[i].GetComponent<Button>();
    3.  
    4.             // Set Button on click definition
    5.             System.Type[] argument = new System.Type[1];
    6.             argument[0] = typeof(int);
    7.             targetInfo = UnityEvent.GetValidMethodInfo(this, "LoadNode", argument);
    8.             UnityAction methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction), this, targetInfo) as UnityAction;
    9.             UnityEventTools.AddPersistentListener(temp.onClick, methodDelegate);
    10.  
    What am i doing wrong?