0
Q:

how to add onclick event dynamically in unity

Button button = myButton.getComponent<Button>();
//next, try any of these:
 
//In Unity 5.6 this doesn't work
button.onClick += myMethod;
//Use this instead
button.onClick.AddListener(myMethod);
//Didn't test it
button.onClick.AddListener(delegate{MyMehtod();})
//this will unlikely work
button.onClick.AddListener(() => {MyMethod();});
0

New to Communities?

Join the community