unity dynamic button onclick code example
Example: 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();});