- Home /
Question by
davidflynn2 · Jul 10, 2013 at 10:47 PM ·
c#menupause
Creating Pause Game Menu
I am trying to create a pause game menu but I have two issues at this point. The first one is I cant get it so that when I press the "P" key it opens it then when you press it again it closes it. The my last problem is I am using UnitySerilizer and I cant get the load buttons this part of the code:
foreach(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName])
{
if(GUILayout.Button(sg.Caption))
{
LevelSerializer.LoadNow(sg.Data);
Time.timeScale = 1;
}
}
to show below my last button.
Here is the full script I have up to this point.
using UnityEngine;
using System.Collections;
public class GrassPause : MonoBehaviour
{
public GUISkin Box;
public GUISkin Box2;
private string box;
public string gameName = "Your Game";
bool showPaused = false;
void Update ()
{
if (Input.GetKeyDown(KeyCode.P))
{
showPaused = true;
pause();
}
}
void pause ()
{
if (showPaused)
{
showPaused = false;
}
if(!showPaused)
{
showPaused = true;
}
}
void OnGUI ()
{
if (showPaused)
{
GUI.skin = Box;
if(GUI.Button(new Rect(392,275,200,55),box))
{
LevelSerializer.SaveGame(gameName);
}
//GUI.skin = Box2;//This is my load button GUI Skin
//if(GUI.Button(new Rect(392,337,200,55),box))//This is my load button
foreach(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName])
{
if(GUILayout.Button(sg.Caption))
{
LevelSerializer.LoadNow(sg.Data);
Time.timeScale = 1;
}
}
}
}
}
Comment
Best Answer
Answer by tw1st3d · Jul 10, 2013 at 11:00 PM
Well for one, you're setting paused to true, then setting it to false immediately after. Try this,
void Update ()
{
if (Input.GetKeyDown(KeyCode.P))
pause();
}
void pause ()
{
if (showPaused)
{
showPaused = false;
}else{
showPaused = true;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Zelda like pause menu 1 Answer
Pause menu scripting help? 1 Answer
Pause Menu Text Not Rendering 0 Answers
Bool wont change... #C 1 Answer