- Home /
 
Display a number on the screen
i have this script on a SIMPLE game just to learn some development but i have no idea how to use gui or anything of such
 var i : int = 1000000;
 function Update () 
    {
     if(Input.GetButtonDown("Jump")){ 
     i -= 1;
 }
 }
 
               how can I make the game show the number i on the screen with my own font?
Answer by Maui-M · Feb 19, 2014 at 11:56 PM
It's there in the link Jay provided.
You will want to use: Label(Rect position, string text, GUIStyle style);
So your code would look something like this:
 var i : int = 1000000;
 var style : GUIStyle;
 function Update () 
 {
     if(Input.GetButtonDown("Jump")){ 
         i -= 1;
     }
 }
 
 void OnGUI() {
     GUI.Label(new Rect(10, 10, 100, 20), i.toString(), style);
 }
 
               You will also need to set up a GUIStyle in the inspector for that script.
Awesome guys !
heres my script
 var i : int = 1000000;
 var Sound : AudioClip;
 function Update () 
    {
     if(Input.GetButtonDown("Jump")){ 
     audio.PlayOneShot(Sound);
     i -= 1;
 }
 }
 var customGuiStyle : GUIStyle;
 function OnGUI() 
 { 
 GUI.Label(Rect (0, 0, 0, 0), i.ToString(), customGuiStyle);
 }
 
                  how do i get this text to scale itself to fit inside a phonesceen and also position itself in the middle?
Use Screen.width and Screen.height when setting your Rect parameters.
Answer by JayOhhh · Feb 19, 2014 at 11:30 PM
It's quite easy actually! One way of doing it would be the GUI.Label method.
http://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html
i dont understad it......i need the gui to display whatever number the variable of "i" is at the moment on the screen with my own fonts but this reference only displays a set string
Your answer
 
             Follow this Question
Related Questions
Can't display PNG texture within GUI calls 1 Answer
Something is missing in my code can any body help me? 0 Answers
GUI looks Awful! 0 Answers
Displaying velocity of a game object 1 Answer
How do i make a (Working) health bar 1 Answer