If you want to dynamically create a series of controls, such as button and toogle, you need to dynamically add events as follows.
Take the button and Toogle O (∩_∩) o~
usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingunityengine.events; Public classTest3:monobehaviour { Publicbutton button; PublicToggle Toggle; voidAwake () {//First KindButton.onClick.AddListener (Myonclick); //The second KindButton.onClick.AddListener (Newunityaction (Myonclick)); //the third type, which can pass parametersButton.onClick.AddListener (Delegate{Myonclick (Newgameobject ()); }); //Toggle the first kindToggle.onValueChanged.AddListener (Myonvalue); //Toggle the second kindToggle.onValueChanged.AddListener (Newunityaction<BOOL>(Myonvalue)); } Public voidMyonclick () {Debug.Log ("Click"); } Public voidMyonclick (gameobject meg) {Debug.Log ("Click"); } Public voidMyonvalue (BOOLisOn) { if(isOn) {Debug.Log ("is selected"); } Else{Debug.Log ("uncheck"); } }}
Ugui button and Toogle dynamic add event