- Home /
 
               Question by 
               NoirKurosuKai · Jul 18, 2016 at 06:31 PM · 
                javascriptguiguistyletimer-script  
              
 
              Help make my Timer GUI stay in the same position
Hello guys i need help with my GUI text for when the time decreases the timer keeps on moving basically the mili seconds. I Can anyone help me make the timer stable and not moving. Thanks appreciate the help!
P.S. if possible edit my code i really would appreciate it!
Code:
 #pragma strict
 
 var timer : float = 10.0;
 var addTime : float = 10.0;
 
 var guiShow : boolean = false;
 
 var fontSize: int= 40;
 public var guiSkin : GUISkin;
 
 
 function Update()
 {
     timer -= Time.deltaTime;
     
     if(timer <= 0)
     {
         Application.LoadLevel("Seraph game");
     }
 }
 
 function OnGUI()
 {
     GUI.skin.box.fontSize=30;
     GUI.skin.box.wordWrap=true;
     GUI.color = Color.yellow;
     GUI.skin = guiSkin;
       //GUI.Box(new Rect(10, 10, 100, 40), "00: " + timer.ToString("0"));
         GUI.Box(new Rect(10, 10, 100, 75), "Time left : " + timer.ToString("f2"));
         
         if(guiShow == true)
         {
             GUI.Box(Rect(105, 20, 60,50), "+" + addTime.ToString("0"));
             showGUI();
         }
 }
 
 function showGUI()
 {
     yield WaitForSeconds(2);
     guiShow = false;
 }

 
                 
                untitled.jpg 
                (341.3 kB) 
               
 
                
                 
                untitled.jpg 
                (343.6 kB) 
               
 
              
               Comment
              
 
               
              Yes, me! :P
For the GUISkin you are using, set the box's text alignment to left (it's probably set to center currently).
 GUI.skin.box.alignment = TextAnchor.$$anonymous$$iddleLeft;
Answer by Pzula · Jul 21, 2016 at 05:09 AM
If you want to remove milliseconds you can use timer.ToString("N0");
But like Nomibuilder said it is much easier to use the New Unity GUI that was introduced in Version 4.6.
Answer by Nomibuilder · Jul 21, 2016 at 04:01 AM
You may use NGUI/Unity UI for better GUI Experience.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                