I want to make a pause menu using Escape key as an input

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");
        }
    
    }

Try something like this:

public void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (isGamePaused)
        {
            ContinueGame();
            Debug.Log("Game should NOT be paused rn");
        } else
        {
            PauseGame();
            Debug.Log("Game should be paused rn");
        }
    }
}

And always use CODE tags when you insert code in your forum posts. More info here .

THANK YOU! I literally saw my mistake with using two if’s rather than if and an else. Thanks again!

And I saw my mistake about Code tags thanks for telling me about it! Have a good day!