- Home /
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)
I have an error in my GUI script for my main menu. I get: GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)
I know what this error means as I've sat here googling it over and over again but yet all the solutions are the same. I must have as many "Ends" as there are "Begins" but that doesn't seem to be the problem as it is fine.
I also get the error: You can only call GUI functions from inside OnGUI. However this does not affect anything on the script.
Here's my script (It's very long I know)
DO NOT USE THIS SCRIPT IN YOUR PROJECTS, IT IS OWNED BY ME AND ONLY ME
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour
{
private Menus currentMenu = Menus.Main;
private bool canSwitch = false;
public Vector2 scrollPosition;
public GUISkin MySkin;
private int buildingindex;
private string buildingname;
private float RenderSliderValue = 0.0F;
private float ShadowSliderValue = 0.0F;
private float TextureSliderValue = 0.0F;
private float MasterVSliderValue = 0.0F;
private bool VSync = false;
//Controls
private string ForwardText = "W";
private string BackText = "S";
private string LeftText = "A";
private string RightText = "D";
private string JumpText = "SPACE";
enum Menus
{
Main,
Options,
Sound,
MyGraphics,
Credits,
MyGUI,
Controls,
}
void OnGUI()
{
GUI.skin = MySkin;
switch(currentMenu)
{
case Menus.Main:
Main();
break;
case Menus.Options:
Main();
Options();
break;
case Menus.Sound:
Main();
Sound();
break;
case Menus.MyGraphics:
Main();
MyGraphics();
break;
case Menus.Credits:
Main();
Credits();
break;
case Menus.Controls:
Main();
Controls();
break;
}
}
//These are to control the main buttons on the menu
void Main()
{
GUILayout.BeginArea(new Rect(Screen.width / 4, 0, 200, Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Box("Main Menu");
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(200));
if(GUILayout.Button("New Game")){
//Load New Game
}
if(GUILayout.Button("Load Game")){
//Load Saved Scene Data
}
if(GUILayout.Button("Options")){
currentMenu = Menus.Options;
}
if(GUILayout.Button("Credits")){
currentMenu = Menus.Credits;
}
if(GUILayout.Button("Quit Game")){
Application.Quit();
}
GUILayout.EndScrollView();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
void Options()
{
GUILayout.BeginArea(new Rect(Screen.width / 2, 0, 200, Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Box("Options");
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(200));
if(GUILayout.Button("Graphics")){
currentMenu = Menus.MyGraphics;
}
if(GUILayout.Button("Sound")){
currentMenu = Menus.Sound;
}
if(GUILayout.Button("Controls")){
currentMenu = Menus.Controls;
}
GUILayout.EndScrollView();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
void Credits()
{
GUILayout.BeginArea(new Rect(Screen.width / 2, 0, 200, Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Box("Credits");
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(200));
GUILayout.Label("Lead Developer: Daniel Knight");
GUILayout.Label("Lead Programmer: Daniel Knight");
GUILayout.Label("Lead Modeller: Teo Tuder");
GUILayout.Label("Lead Developer: Daniel Knight");
GUILayout.FlexibleSpace();
GUILayout.Label("SPECIAL THANKS");
GUILayout.Label("F33L!");
GUILayout.Label("ThePenisBoy");
GUILayout.Label("Nick");
GUILayout.Label("Killerbill");
GUILayout.Label("HailTheFail");
GUILayout.Label("lateroflife");
GUILayout.Label("Anttony Koibu");
GUILayout.Label("Cornelius Kilegran");
GUILayout.Label("Jack Mitchell");
GUILayout.Label("Jack Skinner");
GUILayout.Label("Ashwin Bali");
GUILayout.Label("Ian Hell");
GUILayout.Label("Peyton");
GUILayout.Label("Sven Linnemann");
GUILayout.Label("Teo Tudor");
GUILayout.Label("Simon|Gagup|Skullbeat");
GUILayout.Label("Tim cleall");
GUILayout.Label("CalmCaterpillar");
GUILayout.EndScrollView();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
void MyGraphics()
{
GUILayout.BeginArea(new Rect(Screen.width / 2, 0, 200, Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Box("Graphics");
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(200));
GUILayout.Label("Render Distance");
RenderSliderValue = GUILayout.HorizontalSlider(RenderSliderValue,0.0f,10.0f);
GUILayout.Label("Shadow Distance");
ShadowSliderValue = GUILayout.HorizontalSlider(ShadowSliderValue,0.0f,10.0f);
if(GUILayout.Button("V-Sync On/Off"))
{
if(VSync)
{
VSync = true;
QualitySettings.vSyncCount = 1;
}
else
{
VSync = true;
QualitySettings.vSyncCount = 0;
}
GUILayout.Label("Texture Quality");
TextureSliderValue = GUILayout.HorizontalSlider(TextureSliderValue,0.0f,10.0f);
GUILayout.EndScrollView();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
}
void Controls()
{
GUILayout.BeginArea(new Rect(Screen.width / 2, 0, 200, Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Box("Controls");
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(200));
GUILayout.Label("Forward");
ForwardText = GUILayout.TextField(ForwardText.ToUpper(),10);
GUILayout.Label("Back");
BackText = GUILayout.TextField(BackText.ToUpper(),10);
GUILayout.Label("Left");
LeftText = GUILayout.TextField(LeftText.ToUpper(),10);
GUILayout.Label("Right");
RightText = GUILayout.TextField(RightText.ToUpper(),10);
GUILayout.Label("Jump");
JumpText = GUILayout.TextField(JumpText.ToUpper(),10);
GUILayout.EndScrollView();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
void Sound()
{
GUILayout.BeginArea(new Rect(Screen.width / 2, 0, 200, Screen.height));
GUILayout.FlexibleSpace();
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Box("Sound");
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(200));
if(GUILayout.Button("Sound On/Off"))
{
if(AudioListener.volume != 0)
{
AudioListener.volume = 100;
}
else
{
AudioListener.volume = 0;
}
GUILayout.Label("Master Volume");
MasterVSliderValue = GUILayout.HorizontalSlider(MasterVSliderValue,0.0f,10.0f);
GUILayout.EndScrollView();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
}
}
I know the buttons everything inside the script doesn't do anything as I have only just started with this script
DO NOT USE THIS SCRIPT IN YOUR PROJECTS, IT IS OWNED BY $$anonymous$$E AND ONLY $$anonymous$$E
O$$anonymous$$G, your script is just so brilliant and unique, you should go out and patent it right away!!!
Comments like this, are why no one has offered to assist you.
Your Awesome Brilliant Coding up above, has been done 100 different times, a 100 different ways.
Learn some humility, and doors will open for ya.
All the best, kuro.
Your answer
Follow this Question
Related Questions
What exactly this error is trying to inform me about? 1 Answer
Annoying warning with GUI, quick fix? 2 Answers
HighScore analytics 0 Answers
Expecting variable error with a button 1 Answer
[Solved] GUI Error? 1 Answer