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 IntR · Jun 30, 2014 at 03:07 PM · textgui text

Output text GUI not working

Hi to all!

I am new to Unity, so maybe it would be a stupid question to somebody, but: I am trying to create a text filed which will give random float, it does not appear.

I have created object called GUI Text, added js with following content:

var THP_press: float; var font: Font; var fontsize: int;

function Start () { var targetText : GameObject;

                 THP_press=Random.Range(-1.0,9999.0);
                 var THP_press_string = THP_press.ToString();    
                 
                 targetText.guiText.text = THP_press_string;

                 guiText.font = font;
                 guiText.fontSize = fontsize;
                 
                 }

Can anybody help me to find out how to make it work?

Comment
Add comment · Show 3
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 Klarax · Jun 30, 2014 at 03:20 PM 0
Share

ok. for best result you need to use OnGUI() to display the text onscreen.

inside update: randomly change the float value.

inside OnGUI use:

GUI.Label (Rect (Screen.width/2-50, Screen.height/2-25, 100, 50), THP_press);

OR

GUI.Label (Rect (Screen.width/2-50, Screen.height/2-25, 100, 50), THP_press, style);

if using the second line of code, declare a GUIStyle in the class with the other variables as public, then in the editor change the font and the colors (colors are the first 2 expandable - i think they are normal and hover)

http://docs.unity3d.com/$$anonymous$$anual/class-GUIStyle.html

this should then change the values continuously and have them displayed using the gui of unity.

hope that helps, and is followable (if that is a word)

avatar image IntR · Jul 01, 2014 at 07:02 AM 0
Share

OnGUI, as I understand is text on screen, but not in game space, am i right?

avatar image IntR · Jul 01, 2014 at 07:08 AM 0
Share

To make it more clear, I want to make it look like on picture, but with random number: alt text

Should I use Text$$anonymous$$esh for this ins$$anonymous$$d of guiText?

sample.jpg (422.5 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by IntR · Jul 01, 2014 at 07:14 AM

Succeeded!

This is the sample:

var THP_press: float; var font: Font; var fontsize: int;

function Start () { var targetText : GameObject;

                 THP_press=Random.Range(-1.0,9999.0);
                 var THP_press_string = THP_press.ToString();    
                 GetComponent(TextMesh).text = THP_press_string;    

                 GetComponent(TextMesh).font = font;
                 GetComponent(TextMesh).fontSize = fontsize;
                 

                 }

Klarax, thank you for help :-)

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 Kiwasi · Jul 01, 2014 at 07:13 AM

TextMesh is your answer. TextMesh is designed for providing 3D text, the in world stuff. GUIText is designed for GUI elements, details on a HUD, tooltips, anything you want flat on the screen.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Networking When Offline 1 Answer

Writing on text file in an Android Build 1 Answer

Disable js from c# unity 3 Answers

Camera SmoothFollow place mesh not in the center 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