I don't seem to be able to make a reference to a Button inside a menu prefab.
My menu prefab consists of a panel and the panel has 4 buttons.
I added
public GameObject prefabMenu;
in my code and drag and dropped the prefab in the Unity Editor to it.
When my scene is starting (Start()
method) I instantiate this prefab into a GameObject like this:
panelMenu = Instantiate(prefabMenu, canvas.transform);
after that I try to refer one of the buttons with this line and set an onClick
listener:
btnResume = panelMenu.transform.Find("BtnResume").GetComponent<Button>();
btnResume.onClick.AddListener(() => Log.I("Working"));
The log method however doesn't not get called when I click on the button (I checked and the btnResume
is not null).
I appreciate any help on this. Thank you.