- Home /
Quit Menu errors
I have a quit menu script, it works fine, but brings an error up in the unity editor.
private var quitMenu;
function Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
if (quitMenu == true) {
quitMenu = false;
}
else {
quitMenu=true;
}
Time.timeScale = 0;
}
}
function OnGUI () { if (quitMenu == true) {
GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 200, 200));
GUI.Box (Rect (0,0,100,170), "Game Paused");
if (GUI.Button (Rect (10,30,80,30), "Resume")) {
quitMenu = false;
Time.timeScale = 1;
}
if (GUI.Button (Rect (10,80,80,30), "Restart")) {
quitMenu = false;
Time.timeScale = 1;
Application.LoadLevel(0);
}
if (GUI.Button (Rect (10,130,80,30), "Quit")) {
Application.Quit();
}
}
GUI.EndGroup ();
}
The error I got was
InvalidOperationException: Operation is not valid due to the current state of the object System.Collections.Stack.Peek () UnityEngine.GUIClip.Pop () UnityEngine.GUI.EndGroup () Quit Menu.OnGUI () (at Assets\Scripts\Quit Menu.js:43) UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) UnityEditor.GameView:OnGUI() System.Reflection.MonoMethod:InternalInvoke(Object, Object[]) System.Reflection.MonoMethod:InternalInvoke(Object, Object[]) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.MethodBase:Invoke(Object, Object[]) UnityEditor.HostView:Invoke(String) UnityEditor.DockArea:OnGUI()
Answer by Eric5h5 · Apr 22, 2010 at 09:15 PM
Put the GUI.EndGroup() line in with the rest of the code. Otherwise you have a mismatched group (end without begin).
Answer by AVividLight · Apr 22, 2010 at 09:28 PM
I have not looked at you script, nor do I know what you want to do, but if it is just to quit you can use my script.
And be sure to click the Quit button in the Inspector!
-Note: I have not edited my script, so it may want you to add some pictures/text.
~Gibson of GBSoftware~
var levelToLoad : String; var normalTexture : Texture2D; var rollOverTexture : Texture2D; var beep : AudioClip; var QuitButton : boolean = false;
function OnMouseEnter(){ guiTexture.texture = rollOverTexture; } function OnMouseExit(){ guiTexture.texture = normalTexture; }
function OnMouseUp(){ audio.PlayOneShot(beep); yield new WaitForSeconds(0.35);
if(QuitButton){
Application.Quit();
Debug.Log("This part works!");
}
else{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
Your answer
Follow this Question
Related Questions
Loading a scene in game with a GUI 1 Answer
FindWithTag returns NullReferenceException 0 Answers
Inspector removing MeshRenderer generates error 2 Answers
Instantiating object from inventory 0 Answers
Can't draw a box using Basic GUI 1 Answer