- Home /
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)
#pragma strict
var beep : AudioClip;
var menuSkin : GUISkin;
var menuArea : Rect;
var playButton : Rect;
var instructionsButton : Rect;
var quitButton : Rect;
var instructions : Rect;
private var menuAreaNormalized : Rect;
private var menuPage : String = "main";
function Start(){
menuAreaNormalized = Rect(menuArea.x * Screen.width - (menuArea.width * 0.5), menuArea.y * Screen.height - (menuArea.height * 0.5), menuArea.width, menuArea.height);
}
function OnGUI(){
GUI.skin = menuSkin;
GUI.BeginGroup(menuAreaNormalized);
if(menuPage == "main"){
if(GUI.Button(Rect(playButton), "Play")){
ButtonAction("Island");
}
if(GUI.Button(Rect(instructionsButton), "Instructions")){
menuPage="instructions";
audio.PlayOneShot(beep);
}else if(menuPage == "instructions"){
GUI.Label(Rect(instructions), "You awake on mysterios island... Find a way to signal for help or face certain doom!");
if(GUI.Button(Rect(quitButton), "Back")){
audio.PlayOneShot(beep);
menuPage="main";
}
}
if(GUI.Button(Rect(quitButton), "Quit")){
ButtonAction("quit");
}
GUI.EndGroup();
}
}
function ButtonAction(levelName : String){
audio.PlayOneShot(beep);
yield new WaitForSeconds(0.35);
if(levelName != "quit"){
Application.LoadLevel(levelName);
}else{
Application.Quit();
Debug.Log("Have Quit");
}
}
@script RequireComponent(AudioSource)
I am using your book. . But this code did not work and displays an error such as in the title. What do I have it wrong?
Answer by Owen-Reynolds · Jan 25, 2014 at 06:17 PM
The GUI.BeginGroup()
always happens, but the GUI.EndGroup()
is an IF. Whenever you aren't in menuPage "main," the code Begins groups but never Ends them.
Change so Begin and End always happen in pairs (both should be in or out of the IF.)
In computer error terms, beginGroup "pushes" a new group onto the list of groups. EndGroup "pops" it off the list.
By the way, "I am using your book."? What book is that? Might help if you say. Maybe you typed it wrong, or maybe it needs a correction.
Answer by WhitePL · Jan 26, 2014 at 10:11 AM
Book: Unity 3.x Game Development Essentials by Will Goldstone. A brace from menuPage I switched over GUI.EndGroup(). Now there will be no problem, but the text that was supposed to show when you select the "Instructions" and "Back" button is not displayed. Sorry for my english, I do not know him too well.