Pause GUI not working

hello

I am busy coding a pause button for my game. the game pauses correctly but i want it to show a box with a label saying paused. i cannot get it to show the box.

my code

void OnGUI()
{
//Pause the game
if(GUI.Button(new Rect(Screen.width / 2 +310, Screen.height / 2 -220, 60,60), “Pause”))
{
//GUI.Box(new Rect(Screen.width / 2, Screen.height / 2, 200,200), “Game Paused”);
if(Time.timeScale == 1)
{

Time.timeScale = 0;
GUI.Box(new Rect (10,10,100,90), “GAME PAUSED”);
print(“paused”);

}
else
{
Time.timeScale = 1;
print(“not paused”);
}
}

Turando, you should use the code tags that are explained at the beginning of the scripting forum
they show up like that [c o d e] … [/c o d e] without the spaces.

When you click on your button, can u see the debug text?

Yes the debug text works. If I remove the gui. Box from the if statement it creates the box.

void OnGUI()
{
    //Pause the game
    if(GUI.Button(new Rect(Screen.width / 2 +310, Screen.height / 2 -220, 60,60), "Pause"))
    {
        //GUI.Box(new Rect(Screen.width / 2, Screen.height / 2, 200,200), "Game Paused");
        if(Time.timeScale == 1)
        {
         
            Time.timeScale = 0;

            GUI.Box(new Rect (10,10,100,90), "GAME PAUSED"); // <<<----- Problem
            print("paused");
         
        }
        else
        {
            Time.timeScale = 1;
            print("not paused");
        }
    }
}

It is showing, for exactly one frame.
Your box is only being displayed when you click the button, immediately after that you stop calling for it to be displayed.
Does this make sense?

Hello sorry for the late reply.

i managed tonight to get back into unity and try some tests before reading your reply. basically this is how i solved it probably could be an easier way to make it work but this works for now.

    void OnGUI()
    {

        if(GUI.Button(new Rect(Screen.width / 2 +370, Screen.height / 2 -220, 50,50), "Pause"))
        {
            if(paused == true)
            {
                paused = false;
            }
            else if(paused == false)
            {
                paused = true;
            }
        }
        if(paused == true)
        {
            GUI.Box(new Rect(Screen.width / 2 -50, Screen.height / 2 +10, 200,200), "GAME PAUSED");
            PauseGame();
        }
        else if (paused == false)
        {

        }
    }

    void PauseGame()
    {
        if(Time.timeScale==1)
        {
            Time.timeScale=0;
        }
        else
        {
            Time.timeScale=1;
        }
    }

thanks for the help guys