Answers for "how to add onclick event dynamically in unity"

C#
0

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();});
Posted by: Guest on March-09-2020

Code answers related to "how to add onclick event dynamically in unity"

C# Answers by Framework

Browse Popular Code Answers by Language