- Home /
Pause Menu
Im trying to make a pause menu. Ive gotten all this:
var guiSkin : GUISkin;
var MainMenu : Rect = Rect(10, 10, 200, 200);
function Start () {
}
function Update () {
}
function OnGUI () {
if(guiSkin != null)
GUI.skin = guiSkin;
GUI.Window(0, MainMenu, TheMainMenu, "Pause Menu");
}
function TheMainMenu () {
if(GUILayout.Button("Main Menu")){
Application.LoadLevel("MainMenu");
}
if(GUILayout.Button("Restart")){
Application.LoadLevel("InGame");
}
if(GUILayout.Button("Quit")){
Application.Quit();
}
}
Only problem ive got left, and have no clue how to fix.. How can i make it actually Pause the game? How can i make it Show/Hide once i press Esc?
Answer by DeveshPandey · Sep 10, 2013 at 10:58 AM
var isPause = false;
function Update () {
if( Input.GetKeyDown(KeyCode.Escape))
{
isPause = !isPause
if(isPause)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
}
function OnGUI()
{
if(isPause)
GUI.Window(0, MainMenu, TheMainMenu, "Pause Menu");
}
Thanks for the help :) But when i use this, then i get this: "Assets/Pause Script.js(17,32): BCE0005: $$anonymous$$ identifier: 'The$$anonymous$$ain$$anonymous$$enu'." and: "Assets/Pause Script.js(17,22): BCE0005: $$anonymous$$ identifier: '$$anonymous$$ain$$anonymous$$enu'."
which line pointing this errors? Can you show me your Pause Script.js?
I think you are not using
var $$anonymous$$ain$$anonymous$$enu : Rect = Rect(10, 10, 200, 200);
and
The$$anonymous$$ain$$anonymous$$enu() function,
so use these things and your code will work for sure.
I think i got it fixed, i mixed the help from you with my own, and got this:
var isPause = false;
var $$anonymous$$ain$$anonymous$$enu : Rect = Rect(10, 10, 200, 200);
function Update () {
if( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
{
isPause = !isPause;
if(isPause)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
}
function OnGUI()
{
if(isPause)
GUI.Window(0, $$anonymous$$ain$$anonymous$$enu, The$$anonymous$$ain$$anonymous$$enu, "Pause $$anonymous$$enu");
}
function The$$anonymous$$ain$$anonymous$$enu () {
if(GUILayout.Button("$$anonymous$$ain $$anonymous$$enu")){
Application.LoadLevel("$$anonymous$$ain$$anonymous$$enu");
}
if(GUILayout.Button("Restart")){
Application.LoadLevel("InGame");
}
if(GUILayout.Button("Quit")){
Application.Quit();
}
}
You have to lock the mouse look by your own code, it will not locked by Time.timeScale, I was given you hint not full code.. lolz
Anyway its working now so you can hit accept answer and thumb up!!
Answer by RyanZimmerman87 · Sep 08, 2013 at 03:34 AM
//assign these publics in inspector once you attach script to empty object
public GUIStyle GUIStyleButton;
public Texture2D pauseButtonTexture;
bool gamePausedBool;
void Start()
{
gamePausedBool = false;
Time.TimeScale = 1;
}
void OnGUI()
{
//player presses pause button while playing game
//this script will need to be in the scene you can attach to some empty object.
if (gamePausedBool == false) {
if (GUI.Button(new Rect(pauseVectorPosition.x, pauseVectorPosition.y, vectorSizeSmall.x, vectorSizeSmall.y), pauseButtonTexture, GUIStyleButton))
{
gamePausedBool = true;
Time.timeScale = 0;
}
return;
}
else if (gamePausedBool == true)
{
//more buttons for all the paused game stuff..
//button to unpause game...
if (GUI.Button(new Rect(pauseVectorPosition.x, pauseVectorPosition.y, vectorSizeSmall.x, vectorSizeSmall.y), pauseButtonTexture, GUIStyleButton))
{
gamePausedBool = false;
Time.timeScale = 1;
}
}
}
void Update()
{
if (gamePausedBool == true)
{
return;
}
//your normal game logic
}
Sorry about format don't have time to try to fix atm.
What Unity version is this for? because i dont seem to get where to put it? (Im not running 4.2)
Answer by sammy12345 · Dec 15, 2013 at 02:13 AM
How Do i Make It Soo I Can See my mouse ?
I don't use this script much anymore. But use Screen.showcursor .
And maybe my new script can help you:
#pragma strict
var paused : boolean;
var myString : String = "$$anonymous$$ute";
var $$anonymous$$ute : boolean;
var guiSkin : GUISkin;
function Start () {
}
function Update () {
if(Input.Get$$anonymous$$eyDown("escape")){
paused = !paused;
}
if(paused)
Time.timeScale = 0;
else
Time.timeScale = 1;
if ($$anonymous$$ute == true){
gameObject.GetComponent(AudioListener).enabled = false;
}
else{
gameObject.GetComponent(AudioListener).enabled = true;
}
}
// JavaScript
var icon : Texture2D;
//var frameStyle : GUIStyle;
function OnGUI () {
GUI.skin = guiSkin;
if(paused){
// GUI.Box (Rect (10,10, 100, 50), icon, frameStyle);
if (GUI.Button (Rect (Screen.width/2 - 100,Screen.height/2 - 120, 200, 100), "$$anonymous$$enu")) {
Application.LoadLevel("$$anonymous$$enu");
Time.timeScale = 1;
}
if (GUI.Button (Rect (Screen.width/2 - 100,Screen.height/2,200,100), "Restart")) {
Application.LoadLevel("Game");
Time.timeScale = 1;
}
if (GUI.Button (Rect (Screen.width/2 - 100,Screen.height/2 + 120,200,100), myString)) {
if (myString == "$$anonymous$$ute"){
myString = "Unmute";
$$anonymous$$ute = true;
}
else{
myString = "$$anonymous$$ute";
$$anonymous$$ute = false;
}
}
}
}
Hope this helps :-)
If you need more scripts, them I'm posting all my scripts on my forum: http://$$anonymous$$acdev.com/forum
Answer by CelalQurbanov · Mar 30, 2014 at 03:17 PM
Don`t use Time.timescale = 0; Because if your any animation is playing your game will shoiw error(s) . Use :
Time.timeScale = 0.0001;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Gui placement help 1 Answer
GUI problem 1 Answer
Full Screen Get smaller when i actived it 1 Answer
Pause Menu background problem 0 Answers