Guzaii
September 8, 2013, 2:03am
1
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?
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");
}
//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.
How Do i Make It Soo I Can See my mouse ?
Don`t use Time.timescale = 0; Because if your any animation is playing your game will shoiw error(s) . Use :
Time.timeScale = 0.0001;