• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AngelOfFire · Oct 11, 2014 at 02:49 PM · guierror

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced) Help!!!

i am making a game on unity back got this message after i had finished the code. this peice of code is from http://speed-tutor.com/survival-series/ and download the file. it is under GUI and it is the code txt.

Thx for any advise.

 #pragma strict
 
 //Size of Textures
 
 var size : Vector2 = new Vector2(240, 40);
 
 //Health Variables
 var healthPos : Vector2 = new Vector2(20, 20);
 var healthBarDisplay : float = 1;
 var healthBarEmpty : Texture2D;
 var healthBarFull : Texture2D;
 
 //Hunger Variables
 var hungerPos : Vector2 = new Vector2(20, 60);
 var hungerBarDisplay : float = 1;
 var hungerBarEmpty : Texture2D;
 var hungerBarFull : Texture2D;
 
 //Thirst Variables
 var thirstPos : Vector2 = new Vector2(20, 100);
 var thirstBarDisplay : float = 1;
 var thirstBarEmpty : Texture2D;
 var thirstBarFull : Texture2D;
 
 //Stamina Variables
 var staminaPos : Vector2 = new Vector2(20, 140);
 var staminaBarDisplay : float = 1;
 var staminaBarEmpty : Texture2D;
 var staminaBarFull : Texture2D;
 
 //Fall Rate
 var healthFallRate : int = 150;
 var hungerFallRate : int = 150;
 var thirstFallRate : int = 100;
 var staminaFallRate : int = 35;
 
 private var chMotor : CharacterMotor;
 private var controller : CharacterController;
 
 var canJump : boolean = false;
 
 var jumpTimer : float = 0.7;
 
 function Start()
 {
     chMotor = GetComponent(CharacterMotor);
     controller = GetComponent(CharacterController);
 }
 
 function OnGUI()
 {
     //Health GUI
     GUI.BeginGroup(new Rect (healthPos.x, healthPos.y, size.x, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), healthBarEmpty);
     
     GUI.BeginGroup(new Rect (0, 0, size.x * healthBarDisplay, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), healthBarFull);
     
     GUI.EndGroup();
     GUI.EndGroup();
     
     //Hunger GUI
     GUI.BeginGroup(new Rect (hungerPos.x, hungerPos.y, size.x, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), hungerBarEmpty);
     
     GUI.BeginGroup(new Rect (0, 0, size.x * hungerBarDisplay, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), hungerBarFull);
     
     GUI.EndGroup();
     GUI.EndGroup();
     
     //Thirst GUI
     GUI.BeginGroup(new Rect (thirstPos.x, thirstPos.y, size.x, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), thirstBarEmpty);
     
     GUI.BeginGroup(new Rect (0, 0, size.x * thirstBarDisplay, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), thirstBarFull);
     
     GUI.EndGroup();
     GUI.EndGroup();
     
     //Stamina GUI
     GUI.BeginGroup(new Rect (staminaPos.x, staminaPos.y, size.x, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), staminaBarEmpty);
     
     GUI.BeginGroup(new Rect (0, 0, size.x * staminaBarDisplay, size.y));
     GUI.Box(Rect(0, 0, size.x, size.y), staminaBarFull);
     
     GUI.EndGroup();
     GUI.EndGroup();
 }
 
 function Update()
 {
     //HEALTH CONTROL SECTION
     if(hungerBarDisplay <= 0 && (thirstBarDisplay <= 0))
     {
         healthBarDisplay -= Time.deltaTime / healthFallRate * 2;
     }
     
     else
     {
         if(hungerBarDisplay <= 0 || thirstBarDisplay <= 0)
         {
             healthBarDisplay -= Time.deltaTime / healthFallRate;
         }
     }
     
     if(healthBarDisplay <= 0)
     {
         CharacterDeath();
     }
     
     //HUNGER CONTROL SECTION
     if(hungerBarDisplay >= 0)
     {
         hungerBarDisplay -= Time.deltaTime / hungerFallRate;
     }
     
     if(hungerBarDisplay <= 0)
     {
         hungerBarDisplay = 0;
     }
     
     if(hungerBarDisplay >= 1)
     {
         hungerBarDisplay = 1;
     }
     
     //THIRST CONTROL SECTION
     if(thirstBarDisplay >= 0)
     {
         thirstBarDisplay -= Time.deltaTime / thirstFallRate;
     }
     
     if(thirstBarDisplay <= 0)
     {
         thirstBarDisplay = 0;
     }
     
     if(thirstBarDisplay >= 1)
     {
         thirstBarDisplay = 1;
     }
     
     //STAMINA CONTROL SECTION
     if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
     {
         chMotor.movement.maxForwardSpeed = 10;
         chMotor.movement.maxSidewaysSpeed = 10;
         staminaBarDisplay -= Time.deltaTime / staminaFallRate;
     }
     
     else
     {
         chMotor.movement.maxForwardSpeed = 6;
         chMotor.movement.maxSidewaysSpeed = 6;
         staminaBarDisplay += Time.deltaTime / staminaFallRate;
     }
     
     //JUMPING SECTION
     if(Input.GetKeyDown(KeyCode.Space) && canJump == true)
     {
         staminaBarDisplay -= 0.2;
         Wait();
     }
     
     if(canJump == false)
     {
         jumpTimer -= Time.deltaTime;
         chMotor.jumping.enabled = false;
     }
     
     if(jumpTimer <= 0)
     {
         canJump = true;
         chMotor.jumping.enabled = true;
         jumpTimer = 0.7;
     }
     
     //COMMENTED THESE SECTIONS OUT - UPDATED 16/07/14
     //if(staminaBarDisplay <= 0.05)
     //{
         //canJump = false;
         //chMotor.jumping.enabled = false;
     //}
     
     //else
     //{
         //canJump = true;
         //chMotor.jumping.enabled = true;
     //}
     
     if(staminaBarDisplay >= 1)
     {
         staminaBarDisplay = 1;
     }
     
     if(staminaBarDisplay <= 0)
     {
         //ADDED line 181 here!
         staminaBarDisplay = 0;
         canJump = false;
         chMotor.jumping.enabled = false;
         chMotor.movement.maxForwardSpeed = 6;
         chMotor.movement.maxSidewaysSpeed = 6;
     }
 }
 
 function CharacterDeath()
 {
     Application.LoadLevel("SIMPLELEVEL");
 }
 
 function Wait()
 {
     yield WaitForSeconds(0.1);
     canJump = false;
 }




















































































Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Oct 11, 2014 at 02:51 PM 0
Share

For future posts, please format you code. Often questions with unformatted code are rejected. I formatted it for you this time.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unimechanic · Oct 15, 2014 at 02:41 PM

You opened some control with GUI.BeginXXXXX, and you are not placing the matching GUI.EndXXXXX. Finding such missing calls in a large piece of code can be pretty challenging. The best you can do is removing them all, and place one by one, checking that each is correctly opened/closed and that you don't get more errors. You can also comment or tabulate the blocks to improve code visualization and spot the missing calls.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Keep getting unexpected char: 0x200B! 1 Answer

HighScore analytics 0 Answers

Is there something wrong with my c# script? 1 Answer

Can't draw a box using Basic GUI 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges