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 kildare268 · May 26, 2013 at 01:31 PM · guitextureguitext3d textscores

GUIText doesn't appear in Game View

Hi, my score in GUIText doesn't appear in my Game view. My game is 3D. Should I use GUITexture or 3D Text instead? If yes, how should I edit my original script:

 #pragma strict
 
 private var score : int = 0;
 var textScore : GUIText;
 
 function Start () {
 
     textScore.text = "Score: 0";
 
 }
 
 
 function Update () {
 
 }
 
 function OnCollisionEnter (col : Collision) {
 
     if (col.collider.name == "Cylinder1") {
         Destroy (col.gameObject);
         score += 50;
         textScore.text = "Score: " + score;
         
     }
 }
Comment
Add comment · Show 1
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 robertbu · May 26, 2013 at 03:46 PM 0
Share

Do you have a GUIText object in the scene which you've used to initialize textScore? Also note that GUIText objects live in Viewport space. To be visible, their x and y positions must be between 0 and 1.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eric5h5 · May 26, 2013 at 05:11 PM

A GUIText object uses viewport space, so the x/y coords must be in the 0..1 range. Any camera that you want to display the GUIText object needs to have a GUILayer component.

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 JCprogrammer · May 26, 2013 at 04:52 PM

when you add your code to a GameObject , it will appear on that gameobject's inspector . there you need to add the gameobject which carries the GuiText component . if you have not set any GuiText Component to any gameobject on the scene , then add one from Component ==> Rendering ==> GuiText to , for instance , the same gameobject which carries your javascript code . then add this line :

textScore = this.guiText;

to the start function of you code , which then set the gui component to the variable you set up there automaticly , to work with it

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 kaliban · May 26, 2013 at 04:36 PM

The easiest way to display current score IMO is to use OnGUI()

For example

 void OnGUI() {
         GUI.Label(new Rect (10,10,150,20), "Score: "+score); 
 
     }

This will display text in the left upper corner of the screen. And when variable score changes, it will be immediately displayed.

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 · May 26, 2013 at 05:10 PM 0
Share

Using OnGUI ins$$anonymous$$d of a GUIText object has several drawbacks, namely that it's updated every frame whether you need it to or not (therefore wasting CPU time) and there's no simple way of making it resolution-independent (you have to mess around with GUI.matrix).

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

16 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

Related Questions

Drawing UI text on GUI.DrawTexture , How to do it ? 1 Answer

Gui , Message , Text, Touch and Question ? 2 Answers

Drawing a GUI onto a 3D object 0 Answers

GUI Final Scene/ Item Pickup 0 Answers

Placing a chat bubble above a character's head in a 3d environment 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