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

[RequireComponent(typeof(AudioSource))]
public class timer : MonoBehaviour {

	public float timeleft_second = 3.0f;
	private Text timelabel;
	public float delaytime = 0.5f ;

    public AudioClip background;

    void Start()
    {
        AudioSource audio = GetComponent<AudioSource>();
        audio.Play();
    }

	// Update is called once per frame
	void Update () {
		timelabel = gameObject.GetComponent <Text>();
		timeleft_second -= Time.deltaTime;
		AllScores.all_scores.time = "" +  timeleft_second.ToString("#.#");
        if (timeleft_second > 0)
        {
            timelabel.text = timeleft_second.ToString("#.#");
        }
		if(timeleft_second <= 0){

            AudioSource.Destroy(background);
            
            AllScores.all_scores.results = "Van Helsing Wins";
			AllScores.all_scores.time = "0.0";
			//StartCoroutine (Coroutine (delaytime));
            SceneManager.LoadScene("Results");
            Debug.Log("Game over");
		}
	}

	IEnumerator Coroutine(float duration){
		yield return new WaitForSeconds (duration);
	}
}
