IF statement inside pause menu isn't working

Hi, I’m having a slight problem and I can’t figure it out. I’m currently trying to create my pause menu and resume button however it’s not going to plan. So far I’ve got the pause menu to start off disabled through my “Start” function however my “if” statement isn’t working. The code is below:

public GameObject[] pauseMenu;

void Start()
{
    Time.timeScale = 1;
    pauseMenu = GameObject.FindGameObjectsWithTag("pause");
    Hidepaused();
}

void Update ()
{
    if(Input.GetKeyDown (KeyCode.P))
    {
        if (Time.timeScale == 1)
        {
            Time.timeScale = 0;
            Showpaused();
        }
        if(Time.timeScale == 0)
        {
            Time.timeScale = 1;
            Hidepaused();
        }
    }
}

void Showpaused()
{
    foreach (GameObject p in pauseMenu)
    {
        p.SetActive(true);
    }
}
void Hidepaused()
{
    foreach (GameObject p in pauseMenu)
    {
        p.SetActive(false);
    }
}

It needs to be an if -else (not an if-if), so that it does one or the other. They way you have it, it does both, so ends up being being hidePaused every time. This is because the top if sets the timeScale to 0, but the next if check if it is 0.


         if (Time.timeScale == 1)
         {
             Time.timeScale = 0;
             Showpaused();
         }
         else
         {
             Time.timeScale = 1;
             Hidepaused();
         }

Hi again, I’ve updated my script to the following :

public GameObject pauseMenu;

void Start()
{
    Time.timeScale = 1f;
    pauseMenu = GameObject.FindGameObjectsWithTag("pause");
    Hidepaused();
}

void Update ()
{
    if(Input.GetKeyDown (KeyCode.X))
    {
        Debug.Log("test");
        if (Time.timeScale == 1f)
        {
            Time.timeScale = 0f;
            Showpaused();
        }
        else 
        {
            Time.timeScale = 1f;
            Hidepaused();
        }
    }
}

void Showpaused()
{
    foreach (GameObject p in pauseMenu)
    {
        p.SetActive(true);
    }
}
void Hidepaused()
{
    foreach (GameObject p in pauseMenu)
    {
        p.SetActive(false);
    }
}

No improvement. Still doesn’t work… I also inserted a Debug.Log command and it never appeared in the console so I have no idea what’s going on. @Vega4Life