Pause Menu Script Help!

Hello Unity Community,

I am designing a very simple fun game over the next few months and just started working on it planning everything out I want to get these fundamental things done so I am making a pause menu and it goes like this!

using UnityEngine;
using System.Collections;

public class GUIMenu : MonoBehaviour {

	void OnGUI()
	{
	
	if(Input.GetKey("escape")){
		
		GUI.Box(new Rect(10,20,300,50), "Things Here");
			
		}
	if(Input.GetKey("escape")){
		GUI.Button(new Rect(0,0,0,0), "Things Here");	
		}
	}
}

I know I got the right start although I am sorta a C# noob :confused: and I know code does what it is specifically told and you need to tell it what to in like steps, I was wondering how would I make it to where it toggles it instead of me having to hold down escape? Like how would I say it in the code, and how would I place Time.timeScale = 0; in their as well so when I toggle it is paused and when I untoggle it goes back to 1 thanks!

    void OnGUI()
    {
        GUI.Box(new Rect(10, 10, 120, 90), "Things Here");

        if (GUI.Button(new Rect(20, 40, 100, 20), "Toggle pause"))
        {
            if (Time.timeScale == 1.0f)
                Time.timeScale = 0.0f;
            else
                Time.timeScale = 1.0f;
        }
    }

Ah I forget the else! Thanks dude! Would I do the same for GUI.Box or would the time.timescale screw with one each other?

I modified above code little bit. :slight_smile:

Thanks for the help I managed to resolve it myself reading that script it would display 24/7 I wanted it so when you pause it shows up and when you unpause it dissappears so I made something like this! Know anyway instead of having that button to pause I can use Input.GetKey(“escape”) ?
here is my code btw!

using UnityEngine;
using System.Collections;

public class GUIMenu : MonoBehaviour {

	void OnGUI()
    {
		
		if (GUI.Button(new Rect(50, 50, 100, 20), "Toggle pause"))
        {
            if (Time.timeScale == 1.0f)
                Time.timeScale = 0.0f;
            else
                Time.timeScale = 1.0f;
			}
			if(Time.timeScale == 0.0f)
			{
			GUI.Box(new Rect(850,250,200,300), "Paused");
			}
		if(Time.timeScale == 0.0f)
			{
			if(GUI.Button(new Rect(875,300,150,50), "Continue"))
			{
				Time.timeScale = 1.0f;
			}
		}
 	}
}

How about this

using UnityEngine;
using System.Collections;

public class GUIMenu : MonoBehaviour
{
    bool paused;

    void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            Time.timeScale = 0.0f;
            paused = true;
        }
    }

    void OnGUI()
    {
        if (paused)
        {
            GUI.Box(new Rect(10, 10, 120, 90), "Game paused");
            if (GUI.Button(new Rect(20, 40, 100, 20), "Resume"))
            {                
                Time.timeScale = 1.0f;
                paused = false;
            }
        }
    }

}

When you press ESC, game pauses.

I was reading it and it should work perfect thanks dude so much for your help!