- Home /
 
 
               Question by 
               Dreatix · Jun 24, 2012 at 04:52 PM · 
                guigameobjecttime  
              
 
              Unity3D Game Time
Hi,can someone please help me to make game time in GUI,in this format: ''0:00'' .And it will stop when i die or finish level.Please help.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by ByteSheep · Jun 24, 2012 at 05:02 PM
Updated:
 var sec : float = 0;
 var intsec : int;
 var minutes = 0;
 var seconds;
 var time;
 
 function Update() {
 
 sec = sec + Time.deltaTime;
 
 }
 
 
 function OnGUI() {
 
 intsec = sec;
 
  if(intsec < 10)
  {
   seconds = "0"+intsec;
  }
  else
  {
   seconds = intsec;
  }
 
  if(intsec >= 60)
  {
   minutes++;
   sec=0;
  }
 
  time = minutes + ":" + seconds;
 
  GUI.Label (Rect (10, 10, 100, 20), time);
 
 }
 
              If you check your console, the time should be displayed in there. Ok i just updated it, perhaps try again.
I cant modify script because there are too many namespaces and much unexpected errors,i dont know how can i modify script.
Tested the code in unity and made some adjustments, this works correctly now. sorry bout that :)
Your answer