I have an object (button), which needs to disappear once the game restarts. The code for that is this:
public void Restart()
{
Gamecounter.SetActive(false);
print(“BBEEEEFEFEFEFF”);
}
The code is running because the message gets printed. It is called through the button being pressed.
The order of the events are. 1: void Restart() is called. 2: Scene is reloaded.
But when it reloads the button is still enabled. Why??
Thanks.
ALL FIXED.
Here was the problem code:
void Update()
{
scoreboard.text = "Blue : " + player1score + " Red: " + player2score;
if (player1score >= 5)
{
scoreboard.text = "BLUE WINS";
Gamecounter.SetActive(true);
}
if (player2score >=5)
{
scoreboard.text = "RED WINS";
Gamecounter.SetActive(true);
}
}
Basically reloading the scene doesn’t reload all the scripts. I didn’t realise. So the score was kept at 5 or more, so the button was still active.
Fixed it by setting the player1 and player 2 score to 0 once the button was pressed - so in turn removing the button.