i recently made a unity test game, this is the only problem i am having with it, if I use the pause menu to restart, it works, but if I use the win/lose menu, it doesn’t, they are all attached to a gameobject, thanks in advance ![]()
pause menu:
using UnityEngine;
using System.Collections;
public class PauseMenu : MonoBehaviour {
public bool gEnable = false;
void OnGUI () {
if (gEnable == true) {
// Make a background box
GUI.Box (new Rect (Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2), "Pause");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (new Rect (Screen.width / 3, Screen.height / 3, Screen.width / 3, Screen.height / 10), "Restart")) {
Application.LoadLevel(Application.loadedLevel);
}
// Make the second button.
if (GUI.Button (new Rect (Screen.width / 3, Screen.height / 2.1F, Screen.width / 3, Screen.height / 10), "Exit")) {
Application.Quit ();
}
GUI.Label (new Rect (Screen.width / 2.2F, Screen.height / 1.7F, Screen.width / 7, Screen.height / 10), "Test ver 1.0.0");
GUI.Label (new Rect (Screen.width / 2.6F, Screen.height / 1.5F, Screen.width / 4, Screen.height / 10), "press Esc to close pause menu");
}
}
void Update(){
if (Input.GetKeyDown (KeyCode.Escape)) {
if(gEnable == true){
gEnable = false;
}else{
gEnable = true;
}
}
}
}
winScreen:
using UnityEngine;
using System.Collections;
public class WinScreen : MonoBehaviour {
public static bool WSE = false;
// Use this for initialization
void OnGUI () {
if (WSE == true) {
// Make a background box
GUI.Box (new Rect (Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2), "You Win!");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (new Rect (Screen.width / 3, Screen.height / 3, Screen.width / 3, Screen.height / 10), "Restart")) {
Application.LoadLevel (Application.loadedLevel);
}
// Make the second button.
if (GUI.Button (new Rect (Screen.width / 3, Screen.height / 2.1F, Screen.width / 3, Screen.height / 10), "Exit")) {
Application.Quit ();
}
}
}
}
LoseScreen:
using UnityEngine;
using System.Collections;
public class LoseScreen : MonoBehaviour {
public static bool LSE = false;
void OnGUI () {
if (LSE == true) {
// Make a background box
GUI.Box (new Rect (Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2), "You Lose!");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (new Rect (Screen.width / 3, Screen.height / 3, Screen.width / 3, Screen.height / 10), "Restart")) {
Application.LoadLevel (Application.loadedLevel);
}
// Make the second button.
if (GUI.Button (new Rect (Screen.width / 3, Screen.height / 2.1F, Screen.width / 3, Screen.height / 10), "Exit")) {
Application.Quit ();
}
}
}
}