I am getting strange behvaiour I don't know Why? I am adding function at Add listener on button click event but still its is missing as I reload my scene. I have this function. (Its getting desired button object correctly i have tested)
public void SetupMenuSceneButtons()
{
if (GameObject.Find("BtnStartHost"))
Debug.Log("BtnStartHost found");
if (GameObject.Find("BtnJoinGame"))
Debug.Log("BtnJoinGame found");
GameObject.Find("BtnStartHost").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("BtnStartHost").GetComponent<Button>().onClick.AddListener(delegate { StartupHost(); });
GameObject.Find("BtnJoinGame").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("BtnJoinGame").GetComponent<Button>().onClick.AddListener(delegate { JoinGame(); });
}
I am calling above function on OnLevelWasLoaded event but its function assignment on click is still missing and my buttons are not working as i reload my scene. I have also tried Add event listener without delegate but same problem.
GameObject.Find("BtnJoinGame").GetComponent<Button>().onClick.AddListener(JoinGame);
I have also tried assignment through this but still problem persist.
GameObject.Find("BtnStartHost").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("BtnStartHost").GetComponent<Button>().onClick.AddListener(()=> { StartupHost(); });
GameObject.Find("BtnJoinGame").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find("BtnJoinGame").GetComponent<Button>().onClick.AddListener(() => { JoinGame(); });