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 GlitteringStone · Jul 03, 2013 at 08:57 AM · guieditorbuildoverlapping

GUI Score Overlapping

I have three lines of text displaying the score, player lives, and player power in my game. In the editor, it plays perfectly fine, but when I build the game, the moment one of the values is updated, it looks like there are five or six numbers being displayed at the same time.

This is what it looks like: alt text

And this is the code controlling the GUI. It's attached to the camera for that level.

  void OnGUI() {
         float startingPosition = Screen.width - (Screen.width / 4);
         GUILayout.BeginArea(new Rect(startingPosition, 0, Screen.width / 4, Screen.height));
         GUILayout.BeginHorizontal();
         GUILayout.BeginVertical();
         GUILayout.Label("Score", customSidebar);
         GUILayout.Label("Lives", customSidebar);
         GUILayout.Label("Power", customSidebar);
         GUILayout.EndVertical();
         GUILayout.BeginVertical();
         GUILayout.Label(PlayerPrefs.GetInt("score") + "", customSidebar);
         GUILayout.Label(PlayerPrefs.GetInt("playerLives") + "", customSidebar);
         GUILayout.Label(PlayerPrefs.GetInt("playerPower") + "", customSidebar);
         GUILayout.EndVertical();
         GUILayout.EndHorizontal();
         if (GUILayout.Button("Main Menu", GUILayout.Height(50)))
             Application.LoadLevel(0);
         GUILayout.EndArea();

It works fine in the editor, is there any reason why it would work there and not work when I build the game?

score.png (40.3 kB)
Comment
Add comment · Show 4
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 fafase · Jul 03, 2013 at 09:02 AM 0
Share

Could it be you have the script on two objects and while playing in the editor they happen to be ok but on build, one is slighlty getting different position values?

avatar image GlitteringStone · Jul 03, 2013 at 10:07 AM 0
Share

Nope, it's only on the scene camera, and there's only one of those.

avatar image GlitteringStone · Jul 03, 2013 at 02:41 PM 0
Share

And even if OnGUI is being called more than once per frame (which it probably is), it shouldn't be changing the position values.

All my position values are relative to the screen size, and unless the screen size is shifting really REALLY subtly every half a frame or so, it shouldn't be changing the position, so I have no idea why it's doing this...

avatar image GlitteringStone · Jul 03, 2013 at 02:52 PM 0
Share

Huh I figured it out, apparently it was the number of draw calls, I just reduced it to one line

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GlitteringStone · Jul 03, 2013 at 02:52 PM

Hm figured it out, I just reduced the number of GUI.Label functions down to one with some string formatting and it works.

         GUI.Label(new Rect(Screen.width * 0.75f, 0, Screen.width * 0.125f, Screen.height * 0.1f), "Score     " + PlayerPrefs.GetInt("score") + "\nLives      " + PlayerPrefs.GetInt("playerLives") + "\nPower    " + PlayerPrefs.GetInt("playerPower"), customSidebar);
 
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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Why is my canvas not going away on scene load in build, but is in editor? 2 Answers

GUI not working in Build? 1 Answer

Distribute terrain in zones 3 Answers

GUI Question 0 Answers

OnGUI() works in editor, but not in build with an odd twist! 2 Answers


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