Question by
Rhannon · Sep 26, 2015 at 01:49 AM ·
gameobjectinstantiatebuttonactivatedeactivate
How do I get an instantiated button to active/de-active a gameobject
I'm instantiating a button from a prefab. This works great but when I try to get the button to activate or de-activate a gameobject when it's clicked nothing happens. I know this is because of my reference to the gameobject to be activated or de-activated is getting set to null. My problem is that I can't get GameObject.Find() to locate the actual gameobject. The gameobject is a UI panel. Here's my code:
public void BtnPrefabPress ()
{
csPanel = GameObject.Find("Campaign Setup Panel");
cPanel = GameObject.Find("Campaign Panel");
for(int i = 0; i < SaveLoad.savedGames.Count; i++)
{
if(campaignNameText.GetComponent<Text>().text.CompareTo(SaveLoad.savedGames[i].campaign.cName) == 0)
{
currentGame = SaveLoad.savedGames[i];
index = i;
}
}
if(currentGame.campaign.finishedSetup)
{
csPanel.SetActive(false);
//add saved info to campaign panel for display
cPanel .SetActive(true);
}
else
csPanel.SetActive(true);
}
Comment