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

public class timer : MonoBehaviour
{
    public GameObject timeDisplay;
    public bool isTakingTime = false;
    public int theSeconds = 150;

    void Update()
    {
        if (isTakingTime == false)
        {
            StartCoroutine(SubtractSecond());

            if (theSeconds <= 0)
            {
                SceneManager.LoadScene(0);
            }

        }
    }

    IEnumerator SubtractSecond()
    {
        isTakingTime = true;
        theSeconds -= 1;
        timeDisplay.GetComponent<Text>().text = "" + theSeconds;
        yield return new WaitForSeconds(1);
        isTakingTime = false;
    }
}