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

public class CountDownTimer : MonoBehaviour
{
    public Font countDownText;
    public float startTime;
    float seconds;
    ScoreSystem score;

	void Start ()
    {
        seconds = startTime;

        countDownText = GetComponentInChildren<Font>();
        score = GameObject.FindGameObjectWithTag(Tags.endPoint).GetComponent<ScoreSystem>();
	}
	
	void Update ()
    {
        seconds -= Time.deltaTime;
        score.timeScore = startTime - (startTime-seconds);
		int mins = ((int)seconds) / 60;
		int secs = ((int)seconds) % 60;
        countDownText.WriteNumber(mins.ToString() + (secs < 10 ? "0" : "") + secs.ToString());


        if (seconds <= 0)
        {
            print("OUT OF TIIIME!");
            Application.LoadLevel(4);
        }
    }
}
