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()