- Home /
Countdown Timer
Hey I need help
I would like a timer for my game but its like a game show timer so like say you have 3 mins to complete something then when 10 secs are left the timer comes up on the screen i would like something like that but i have no idea how to do it
Answer by AlucardJay · Jul 21, 2012 at 10:16 PM
check my answer on this question : http://answers.unity3d.com/questions/279434/problem-restart-time-by-key.html
and this : http://answers.unity3d.com/questions/231521/how-to-display-data-in-an-array.html
all the information you need to do this are in those 2 answers =]
also : http://lmgtfy.com/?q=unity+countdown+timer
EDIT : here is what you're after ....
 #pragma strict
 var theTimer : float = 0.0;
 var theStartTime : float = 120.0;
 var showRemaining : boolean = false;
 function Start() 
 {
     theTimer = theStartTime;
 }
 function Update() 
 {
     theTimer -= Time.deltaTime;
     if (theTimer < 10) 
     {
         Debug.Log("TEN SECONDS LEFT !");
         showRemaining = true;
     }
     if (theTimer <= 0) 
     {
         Debug.Log("OUT OF TIME");
         theTimer = 0;
     }
     if ( Input.GetKeyUp(KeyCode.G) )
     {
         Debug.Log("Resetting");
         theTimer = theStartTime;
         showRemaining = false;
     }
 }
 function OnGUI() 
 {
     var text : String = String.Format( "{0:00}:{1:00}", parseInt( theTimer / 60.0 ), parseInt( theTimer % 60.0 ) ); 
     if (showRemaining)
     {
         GUI.Label( Rect( 10, 10, Screen.width - 20, 30), text );
     }
 }
Thats not what im looking for i have a script for a menu to come up but i need a script so it say 10 seconds left then starts counting down
 var showRemaining : boolean = false;
 ... in update
 if (remainingTime < 10secs)
 {
     showRemaining = true;
 }
 ... OnGUI
 if (showRemaining)
 {
     GUI.Box( Rect(0,0,100,20), remainingTime.ToString() );
 }
so does that timer come up when its 10 seconds to 3 $$anonymous$$s?
Your answer
 
 
             Follow this Question
Related Questions
GUIText not working properly with a timer. 1 Answer
Timer that can be accessed in multiple scenes 1 Answer
Texture Importer 3 Answers
targeting desnsity inside buoyancy script 0 Answers
Stand alone player 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                