Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 SlyyGuyy · Apr 13, 2014 at 09:04 PM · javascriptguiscoreguilabel

GUI Label Score Overlapping - Javascript

In my game, I have a score script which is attached to an object in my main game scene. I have it set so that when the player "dies" in the game it takes you to the game over screen and DOES NOT destroy the score so that you can see what your score was on game over. However, when the game restarts, the old score is still there and is overlapping over my brand new score. How can I fix this?

 #pragma strict
 
 var playerScore : int = 0;
 
 //Style
 var scoreStyle : GUIStyle;
 
 function Start () {
     playerScore = 0;
 }
 
 function Update () {
 
 }
 
 function OnGUI () {
     if(Application.loadedLevel == 3) { //Game Level
         GUI.Label (new Rect(20,20,10,10), playerScore.ToString(), scoreStyle);
     }
     
     if(Application.loadedLevel == 7) { //Game Over Screen
         GUI.Label(Rect(Screen.width/2, Screen.height/2, 10, 10), playerScore.ToString(), scoreStyle);
     }    
 
 }

alt text

screen shot 2014-04-13 at 4.03.00 pm.png (81.4 kB)
Comment
Add comment · Show 3
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 getyour411 · Apr 13, 2014 at 09:08 PM 0
Share

Logically if you have two things in the same x,y that'll happen, so move one or the other somewhere x,y-else

...unless you are asking how do you get rid of the var on game restart?

avatar image SlyyGuyy · Apr 13, 2014 at 09:24 PM 0
Share

I want to get rid of the score when the game restarts and create a new label that resets the score to 0

avatar image SlyyGuyy · Apr 17, 2014 at 02:15 AM 0
Share

Bump. I'm still struggling to achieve my desired results. I +1 getyour411, and I appreciate the response, but his answer isn't working for me. Does anyone else know how to solve this issue? I should note that my button controls are separate from the "$$anonymous$$ain score" controls and the main score script is separate from all my other scripts. It's baffling me that I've struggled this much with such a see$$anonymous$$gly simple task

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by getyour411 · Apr 13, 2014 at 09:25 PM

Use OnLevelWasLoaded() to reset to 0

Comment
Add comment · Show 2 · 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
avatar image SlyyGuyy · Apr 13, 2014 at 10:07 PM 0
Share

This succeeds in resetting my score, yes, but it still doesn't stop the GUI Labels from overlapping each other. What I want is when the player hits "main menu" or "replay" on the game over screen, the GUI Label is removed so that when a new game starts, there aren't 2 instances of the same object

avatar image getyour411 · Apr 13, 2014 at 10:23 PM 0
Share

So change that comment into a

 if(thatCondition)  {
 // set a bool to true
 }

then in your OnGUI wrap the display of the score you dont want like

 if(!thatBool)
 GUI.label...

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.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Pause When Score Reached? 2 Answers

Need help displaying score (JavaScript) 1 Answer

Need help with GUI label not displaying variable 1 Answer

getting gui error you can only call functions from inside OnGui. 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