Forum begins after the advertisement:
-
::When the Level Up screen is displayed, pressing the Esc button causes the game to pause, so I modified the code. What I want is for the Paused screen to be able to activate or deactivate even when the Level Up screen is active, but despite modifying the code, the Paused screen does not activate when the Level Up screen is displayed. How can I resolve this issue? I need your help, Mr.
GameManager.cs
<code>
public void PauseGame()
{
if (currentState != GameState.Paused)
{
previousState = currentState;
ChangeState(GameState.Paused);
Time.timeScale = 0f;
pauseScreen.SetActive(true);
}
}
public void ResumeGame()
{
if (currentState == GameState.Paused)
{
if (currentState == GameState.Paused)
{
ChangeState(previousState);
Time.timeScale = (currentState == GameState.LevelUp) ? 0f : 1f;
pauseScreen.SetActive(false);
}
}
}
void CheckForPauseAndResume()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
if (currentState == GameState.Paused)
{
ResumeGame();
}
else
{
if (currentState == GameState.LevelUp)
{
pauseScreen.SetActive(true);
}
else
{
PauseGame();
}
}
}
}</code>
::There’s nothing wrong with the code, but I just can’t figure out why it’s not working.
::Make sure in the switch statement to add CheckForPauseAndResume()
in case GameState.LevelUp
.
::Thank you, I managed to solve it somehow. Your help was really valuable.
<code>
case GameState.GameOver:
case GameState.LevelUp:
CheckForPauseAndResume();
break;
</code>
<code>public void ResumeGame()
{
if (currentState == GameState.Paused || currentState == GameState.LevelUp)
{
ChangeState(previousState);
Time.timeScale = (currentState == GameState.LevelUp) ? 0f : 1f;
pauseScreen.SetActive(false);
}
}</code>
<code>void CheckForPauseAndResume()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
if (currentState == GameState.Paused)
{
ResumeGame();
}
else if (currentState == GameState.LevelUp)
{
if (pauseScreen.activeSelf)
{
ResumeGame();
//pauseScreen.SetActive(false);
}
else
{
pauseScreen.SetActive(true);
}
}
else
{
PauseGame();
}
}
}</code>
Advertisement below: