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 garybaldi688 · May 19, 2012 at 06:11 AM · updateguitextgui.label

GUIText doesn't update

Hi. I am using GUIText to store and render a simple timer. I am setting the content thus:

guiText.text = "Timer:" + Global.timer;

However when Global.timer is decremented the view on the screen doesn't auto-update. The view is updated using GUI.Label (below). However I have opted for using GUIText for ease of font manipulation. I could stay with Label but for being able to assign a font (.ttf asset import) to it, in a Javascript.

I can manually update the GUIText content of course using the above but that screws with the font i.e. the global score variable doesn't seem to be the same font as "Timer". Any ideas how to solve either please?

Thanks

G.

GUI.Label (Rect (300, 25, 100, 30), "Timer: " + Global.timer);

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
1

Answer by Eric5h5 · May 19, 2012 at 06:33 AM

You have to use Update; the text won't change once it's been assigned unless you change it. Also, you can use whatever TTF font you like in OnGUI code.

Comment
Add comment · Show 5 · 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 garybaldi688 · May 19, 2012 at 07:02 AM 0
Share

Thanks. Sorry, I am in the doco (newb) and I don't see any reference to Update. What is 'Update'? A method? Object?

Thanks

avatar image Eric5h5 · May 19, 2012 at 07:18 AM 0
Share

Please don't post comments as answers. Anyway, just use the search box in the scripting docs.

avatar image syclamoth · May 19, 2012 at 07:20 AM 1
Share

If you don't know what a method or an object is, you need to take basic program$$anonymous$$g classes.

avatar image garybaldi688 · May 20, 2012 at 10:18 AM 0
Share

Syclamoth, to extrapolate I was asking if Update in this context is a method or an object.

I see Update is not a method of GUItext nor is it in the inheritance hierarchy. I can't find it as an Object which leaves only the Update function called in each JS attached to a GameObject. There are 2 problems with this, assu$$anonymous$$g this is what you ere referring to, firstly the string is still rendered using 2 different fonts and second the Update function is being called x times per second resulting in a massive, unnecessary overhead.

Thanks for any further clarity.

avatar image Bunny83 · May 20, 2012 at 12:09 PM 0
Share

@garybaldi688: This is again not an answer to the question. Answers should answer the question.

A guitext component redraws itself (via the guilayer component on the camera). The text on the other hand doesn't update itself. Everytime you change your Global.timer variable you have to execute this line again:

 guiText.text = "Timer:" + Global.timer;

If you use GUI.Label it has to be used in OnGUI which is also called every frame.

You can use a custom GUIStyle or a GUISkin (which is just a collection of GUIStyles) to change the font of a certain GUI element.

avatar image
-1

Answer by garybaldi688 · May 20, 2012 at 10:17 AM

Ok this fixed the issue:

var font : Font; guiText.font = font;

Adding this before I manually update the guiText now sees the text nicely formatted, the same font etc. This makes no sense.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do adjust GUI.Label lineHeight? 1 Answer

Update Guitext every frame 1 Answer

GUIText not updating score.... 1 Answer

Updating an interger in a GUIText 1 Answer

Timer lag at GUIText drawing. 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