- Home /
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?
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)
OnGUI, as I understand is text on screen, but not in game space, am i right?
To make it more clear, I want to make it look like on picture, but with random number:
Should I use Text$$anonymous$$esh for this ins$$anonymous$$d of guiText?
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 :-)
Your answer
Follow this Question
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