Question by
rappatic · Apr 10, 2018 at 10:39 AM ·
gameobjectactiveactivatedeactivate
SetActive not working as should
I'm working on a clicker game and when the user clicks on the button "MINE STONE" a script is run to mine it. The script should make a small GameObject (a RawImage of a clock) active in the lower left-hand corner of the screen, wait a small amount of time and add 1 to the "stone" variable.
public Text showStone;
public GameObject clock;
public uint stone = 0;
int waitTime = 250;
public void AddStone ()
{
clock.SetActive(true);
for (int i = 0; i <= waitTime; i++) {
Debug.Log(i);
}
clock.SetActive(false);
stone++;
showStone.text = stone.ToString ();
}
void Update () {
showStone.text = stone.ToString();
}
I've manually deactivated the clock in the Editor, and this script should re-enable it then disable it after the delay. However, the clock doesn't appear.
My theory is that when I deactivated it manually, this prevents me from reactivating it via code. Is this so? If so, then how do I deactivate it via code when the game is run?
Otherwise, is there a bug in my code?
Comment