- Home /
Simple Timer
Hi all,
I am using this code for a level timer.
 var guiTime = Time.time - startTime;
         var minutes : float = guiTime / 60;
         var seconds : int = guiTime % 60;
         textTime = String.Format ("{0:00}:{1:00}", minutes, seconds);
Which I found in another old thread, which somewhat works, but t gives funny results.
For example, it counts up to the 1st minute fine, then goes up to 1:60, then back to 1:00 and then changes to 2 mins after an additional 30 seconds.
Does anyone have any ideas what is going wrong here?
Many thanks.
               Comment
              
 
               
              Answer by Hullu · Jul 27, 2014 at 04:17 PM
Maybe because minutes is float*? Haven't tested this tho:
 var guiTime = Time.time - startTime;
 var minutes : int = guiTime / 60;
 var seconds : int = guiTime % 60;
  
 textTime = String.Format ("{0:00}:{1:00}", minutes, seconds); 
Answer by milox777 · Jul 27, 2014 at 05:31 PM
Try this code:
 var guiTime = Time.time - startTime;
 var minutes : int = guiTime / 60;
 var seconds : int = guiTime % 60;
 textTime = minutes.ToString() + ":" + (seconds < 10 ? "0" : "") + seconds.ToString();
 
Your answer
 
 
             Follow this Question
Related Questions
Coroutine Countdown Timer being extremely slow 1 Answer
Problem with countdown timer. 3 Answers
how to make a varied countdown timer 1 Answer
Timer doesn't work properly 2 Answers
Timer script not perfectly working 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                