I’ve got problem with adding function to a button. I’m reloading scene many times on runtime and button loses its function. I can’t add it from Inspector so i need to do it by code. I’ve tried this
void OnLevelWasLoaded(int level) {
if (level == 0) {
GameObject button = GameObject.Find("Sound");
Button b = button.GetComponent<Button>();
// b.onClick.AddListener(() => AudioSwitch());
b.onClick.AddListener(delegate { AudioSwitch(); });
}
}
but it does not work for me. How can I do that?