So I have a save point in my game where if you approach it and press a button, you enable a Canvas with three button options. I also set Timescale to zero and make it so the player can’t move. This happens in Update() on a script attached to my save point object…
if (playerHere && player.GetComponent<PlayerMovementTest> ().control == true && Input.GetButtonDown ("Submit"))
{
eventSystem.GetComponent<EventSystem> ().SetSelectedGameObject(saveButton);
player.GetComponent<PlayerMovementTest> ().control = false;
Time.timeScale = 0;
saveMenu.SetActive (true);
}
So far so good. I have three buttons, Load, Save, and ClearSaves. Each button calls a function that looks something like this:
public void SaveButton ()
{
//save the game, and take note of this save point specifically
player.GetComponent<PlayerMovementTest> ().spawnPointNumber = spawnLocation;
player.GetComponent<PlayerMovementTest> ().Save ();
Debug.Log ("You saved at spawn point number " + spawnLocation);
//turn off the canvas, and resume play
saveMenu.SetActive (false);
Time.timeScale = 1;
player.GetComponent<PlayerMovementTest> ().control = true;
Debug.Log ("End of function");
}
Now the last half of this is what’s giving me issue. When looking in the Console, I get the “End of function” log just fine, but the canvas never disables itself. and the timescale never gets set back either, despite me putting in a test Debug.Log that claimed it had returned to a value of 1, like it should. Everything just stays frozen and the buttons are still on screen.
But to make things even MORE confusing, just to test I tried calling the same SaveButton() function in Update through a keystroke.
if (Input.GetKeyDown(KeyCode.Escape))
{
SaveButton ();
}
And for some reason, this works! So apparently the button just isn’t doing its job, despite the Debug.Log telling me otherwise. Does anyone know what on earth is happening here?
I’m using Unity 5.6 by the way.