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 TSI25 · Dec 03, 2013 at 11:40 PM · unity4.3read-only

Live GUI text readout?

So basically there are two parts to this problem. Firstly, I'm trying to use unity's new (free) 2d support to make a GUI text object that will read out a number for testing purposes. Secondly the number I'm trying to display it with is currently being pulled from another class.

I'm just getting an error stating that "Assets/Scripts/FuelLSreadout.js(9,1): BCE0053: Property 'UnityEngine.Component.guiText' is read only."

does that mean its impossible to get a live readout? Heres my code.

 #pragma strict
 public var fuel = 300.0f;
 public var lifeSupport = 1000.0f;
 function Start () {
 
 }
 
 function Update () {
 guiText = "Life Support: " + lifeSupport + " | Fuel: " + fuel;
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tyrike thompson · Dec 04, 2013 at 12:04 AM

You should do like so..

 #pragma strict
 public var fuel = 300.0f;
 public var lifeSupport = 1000.0f;
 public var (Whatever you wanna name it) : GUIText;
 
 function Start () {
  
 }
  
 function Update () {
 (Whatever you wanna name it).text = "Life Support: " + lifeSupport + " | Fuel: " + fuel;
 }
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 RyanZimmerman87 · Dec 04, 2013 at 12:16 AM

I've had GUI issues before where the text does not display correctly unless it is updated inside OnGUI()

So for example you might want:

 string guiText;
 
 void OnGUI()
 {
 guiText = "Life Support: " + lifeSupport + + " | Fuel: " + fuel;
 
 }

I have no idea why this is the case, maybe I did something wrong. But I have at least several GUI displays in my project that do not work correctly if their info is update from inside Update().

Worst comes to worst you could try doing the update like in my example inside OnGUI();

Also your example doesn't show how you're trying to retrieve the data from the other script?

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 Eric5h5 · Dec 04, 2013 at 12:33 AM 0
Share

OnGUI code is not related to GUIText objects.

avatar image
0

Answer by Eric5h5 · Dec 04, 2013 at 12:35 AM

guiText is the component; you need to use the text property.

 guiText.text = "xxx";

As a side note, this is not related to the new 2D functionality in any way. GUIText objects have been around since Unity 1.

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

19 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

Related Questions

Unity 4.3 Long 2D Animations? 0 Answers

Assigning tag on runtime break loop in C# unity3D 4.3. 1 Answer

At same positioned game objects collision detection 0 Answers

Game support for landscape and portrait 0 Answers

Particle System Not Firing Immediately 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