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 Dudledok · Jul 21, 2014 at 05:26 PM · c#guinetworkonlinelabel

When online GUI.Label (or text area etc) shows overlapping text

You can see my small script below. It simply resets the players position when they fall below a certain height and adds one to their death count and also the team's death count.

 using UnityEngine;
 using System.Collections;
 
 public class Scoring : MonoBehaviour
 {
     public float lowestFallDistance = -10;
     private int deathCount;
     public static int teamDeathCount;
     private string deathCountString;
     public static string teamDeathCountString;
     private int screenWidth;
 
     void Start()
     {
         deathCount = 0;
         teamDeathCount = 0;
         deathCountString = deathCount.ToString();
         teamDeathCountString = teamDeathCount.ToString();
         screenWidth = Screen.width;
     }
 
     void Update()
     {
         if(this.transform.position.y < lowestFallDistance)
             Reset();
     }
 
     void OnGUI()
     {
         GUI.Label(new Rect(5, 5, 30, 20),deathCountString);
         GUI.Label(new Rect(screenWidth - 35, 5, 30, 20),teamDeathCountString);
     }
     
     void Reset(){
         this.transform.position = new Vector3(0,2,0);
         ++deathCount;
         networkView.RPC("PlusTeam", RPCMode.AllBuffered, "");
         deathCountString = deathCount.ToString();
     }
     
     [RPC]
     void PlusTeam(string empty) {
         ++teamDeathCount;
         teamDeathCountString = teamDeathCount.ToString();
     }
 }
 

The team's death count in the top right only shows once, and just as I intend it to, but the player's individual death count in the top left is always zero with the actual count displayed on top.

This only happens when I play online. If I play single player and die it just shows the correct score without a zero underneath. I really don't see what I've done wrong so any help would be greatly appreciated.

Comment
Add comment
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

2 Replies

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

Answer by Dudledok · Jan 26, 2015 at 05:34 PM

Just went through some previous questions and seen this unanswered.

I had the script on more than one object so it showed it once for each object it was on. Sharing in case anyone else makes the same mistake I did.

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
avatar image
0

Answer by MjrDeathAdder · Jul 22, 2014 at 09:24 AM

Not sure if this will fix it but it will reduce the amount of lines in your code instead of storing an individual string parallel to the integer why not when you need to display the counters as a string call the .toString() function.

 GUI.Label(new Rect(5, 5, 30, 20),deathCount.ToString());
Comment
Add comment · Show 1 · 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 Dudledok · Jul 22, 2014 at 09:52 AM 0
Share

Reduce the amount of lines, yes, but not make it quicker. Your way would call ToString() every cycle of OnGUI() as opposed to just once each time the int is updated.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How would you set up a Lobby Scene? 1 Answer

Display "organized" string on GUI Label 1 Answer

Trouble using C# tooltips 1 Answer

network GUI not working 1 Answer

How do you change the size and color of a GUI Label in C#? 4 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