
// the textfield to update the time to
private var textfield:GUIText;

// time variables
public var allowedTime:int = 90;
private var currentTime = allowedTime;


function Awake()
{
	// retrieve the GUIText Component and set the text
	textfield = GetComponent(GUIText);
	
	UpdateTimerText();
	
	// start the timer ticking
	Tick();
}

function Tick()
{
	// while there are seconds left
	while (currentTime > 0)
	{
		// wait for 1 second
		yield WaitForSeconds(1);
		
		// reduce the time
		currentTime--;
		
		UpdateTimerText();
	}
	
	
	// create a camera fade and then fade it in
	iTween.CameraFadeAdd();
	iTween.CameraFadeTo(1,1);
	
	// wait for a second
	yield WaitForSeconds(1);
	
	// game over
	Application.LoadLevel("menu");
}

function UpdateTimerText()
{
	// update the textfield
	textfield.text = currentTime.ToString();
}