using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Timer : MonoBehaviour
{
		private float TimeStart, TimeEnd;
		public static int SecondsRemaining;
		public float Seconds;
		private Text text;
		// Use this for initialization
		void Start ()
		{
				TimeStart = Time.time;
				TimeEnd = TimeStart + Seconds;
				text = this.GetComponent<Text> ();
				
				
		}
		
		void Update ()
		{
				SecondsRemaining = (int)(TimeEnd - Time.time);
				if (SecondsRemaining >= 0)
						text.text = "- " + (SecondsRemaining).ToString () + " -";
				if (SecondsRemaining == 0) {
						GameObject.FindGameObjectWithTag ("Caronte").GetComponent<TheKeeper> ().actualLevel = Application.loadedLevelName;
						GameObject.FindGameObjectWithTag ("Caronte").GetComponent<TheKeeper> ().displayText = "You ran out of time!".ToUpper ();
						Application.LoadLevel ("giocochiuso");
				}
						
						
				
				
		
		
		
		
		}
}
