Making a pause Menu

General question, I have seen quite alot of people asking if there can be a way to make a Pause screen, Then i have seen people answer with the answer create a new scene and GUI buttons and Things on to it But it wouldn’t work because it would reset the Game right??, my question is Couldn’t i just make a GUI texture that That activates when i press like the button “M” or something to bring up the GUITexture with like a map and a little red dot to show where i am ??, then press “M” again to deactivate it :confused: Sorry if this question doesn’t make sense but it did in my head :stuck_out_tongue:

It would not reset the Game if you use an object with DontDestroyOnLoad() and use this object during of game play:

Script: Pause.js attached to a Pause object in Pause scene:

static var gamePaused : boolean = false;

function Awake() {
  DontDestroyOnLoad(this);
}

function Start() {
	Application.LoadLevel("Level");
}

function OnGUI () {
   if(gamePaused) {
      GUILayout.Label ("GUI buttons here");
   }
}

function LateUpdate () {
   if(Input.GetKeyUp(KeyCode.M)){

      if(gamePaused) {

         Time.timeScale = 1.0;
         gamePaused = false;         

      } else {

   	     Time.timeScale = 0.0;
   	     gamePaused = true;

      }
   }
   Debug.Log("gamePaused = " + gamePaused);	
}

Script: Level.js attached to a Level object in Level scene:

function Start () {
	gameState = FindObjectOfType(Pause);
	gameState.gamePaused = false;
}

function Update () {
	Debug.Log ("Level is running, Time.time is = " + Time.time);
}

Add Level scene to the Build Settings, start the game with Pause scene and watch the log.

Why don't you make buttons in a Window instead of just buttons? Well, I don't know javascript, I will write in C#.

using UnityEngine;
using System.Collections;

public class PauseMenu : MonoBehaviour {

    public Rect windowRect = new Rect(295,175,0,0);
    public bool gamePaused = false;

    void Update(){
    if(Input.GetKeyUp(KeyCode.M)){
        if(gamePaused){
            gamePaused = false;
            Time.timeScale = 1.0f;
        } else {
            gamePaused = true;
            Time.timeScale = 0.0f;}
        }
    }

    void OnGUI(){

        if (gamePaused){
            Time.timeScale = 0.0f;
            GUILayout.Window(0, windowRect, PauseMenu,
                "Game Paused", GUILayout.Width(100));
        }
    }

    void PauseMenu(int windowPause) {
        if (GUILayout.Button("Resume")){
            Time.timeScale = 1.0f;
            gamePaused = false;

        }
    }
}


It will make a window with name "Game Paused" and 1 button "Resume" in window appear. You can either press M either "Resume" button to continue. You can Add any GUILayout's in window at "void PauseMenu(int windowPause)".

Short answer: change the name of the ‘PauseMenu’ function both in line 29 and 24.

Long answer:
If you are not a coder at all (not so difficult to become one) I will try to learn you how to deal with the errors: when you have an error, pay attention to the most important information: line and character position where error was. For example “(Line 29,10)” mean that there is a problem at line 29 on the script, starting with character number 10, aka ‘P’. Look for the string started there with ‘P’. This is ‘PauseMenu’. So that it’s something strange with this string. The probably you must to change it. But where? (there is 3 occurrences of ‘PauseMenu’ in the script: first one at line 4; second one at line 24 and last one at line 29 where you have the error). The tip is to look what the ‘PauseMenu’ mean at line 29. It’s a function, because have ‘()’ along. Where this function it’s called / used? Here you must to investigate a bit what ‘PauseMenu’ mean at line 4 and at line 24. At line 4 doesn’t look like a function; it’s a name of the object; so probably you don’t want to change this (you maybe use this as name to refer it from other scripts). But in line 24? There looks as parameter of another function - named “GUILayout.Window (<here is the parameters, comma separated>)”, respectively the paramenter #3. Then, since the “GUILayout” it’s an Unity thing, go to Unity documentation and search for “GUILayout.Window” (http://unity3d.com/support/documentation/ScriptReference/GUILayout.Window.html). You will discover there a line:

static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, text : String, : ) : Rect

The function name is ‘Window’; The #3 parameter is “func : GUI.WindowFunction” (func=it’s a function). Now, you have the confirmation: ‘PauseMenu’ on line 24 it’s name of a function. What this mean? Mean that on line 24, you call the function defined at line 29. And looks like the engine don’t like you use the current name of the function. Just change it name, in both places: where function are declared; and where function are called (for example, to ‘ShowPauseMenu’):

Line 24: GUILayout.Window(0, windowRect, ShowPauseMenu,

Line 29: void ShowPauseMenu(int windowPause) {

No, there is absolutely no reason why you can’t just draw some gui elements on the screen, like a minimap and some buttons. That’s what I do, and it works just fine! I don’t know about all this talk of making new scenes full of gui elements- as you say, that would reset the game (and you don’t want that- it’s a pause button not a reset button)

As @ OrangeLightning said : Time.timeScale would work fine.

var paused : boolean = false;

function Update () {

   if(Input.GetKeyUp(KeyCode.M)){
      if(!Paused){
         Time.timeScale = 0;
         paused = true;
      }
   }
}

As for the GUI buttons.

var MyTexture : Texture;

function OnGUI(){
  GUI.Box(Rect(250,50,300,400),"Menu");

  if(GUI.Button(Rect(360,100,80,20),"Resume")){
    PauseScript.paused = false
  }

  if(GUI.Button(Rect(360,130,80,20),"Quit")){
    Application.Quit();
  }
}