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
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 );
}
}