The problem is that I want to take the escape key’s input for pausing and continuing the game but two functions happen at the same time.
I thought about using waitforsecond method but I thought it doesn’t fit at this part.
Can you developers help me fix this problem?
(I am trying to do a unity learn part, I’m sorry for my bad English.) (I don’t want any answer, I want help like you can try using this “____” method. So I can research that method myself.)
public void PauseGame()
{
pauseMenu.gameObject.SetActive(true);
Time.timeScale = 0;
isGamePaused = true;
}
public void ContinueGame()
{
pauseMenu.gameObject.SetActive(false);
Time.timeScale = 1;
isGamePaused = false;
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.Escape) && isGameActive)
{
PauseGame();
Debug.Log("Game should be paused rn");
}
if (Input.GetKeyDown(KeyCode.Escape) && isGamePaused && isGameActive)
{
ContinueGame();
Debug.Log("Game should NOT be paused rn");
}
}