using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class TimerScript : MonoBehaviour
{
    public Text _TimerText;
    public float countdownTimer;
    public bool canCount;

    private drag[] myobjects;
    private PlayerMovement player;
    public float startTime;
    private EndCollider endCollider;

    private void Start()
    {
        myobjects = GameObject.FindObjectsOfType<drag>();
        player = FindObjectOfType<PlayerMovement>();
        endCollider = FindObjectOfType<EndCollider>();
        startTime = countdownTimer;

        StartCounting();
    }
    public void StartCounting()
    {
        canCount = true;
        StartCoroutine(CountingIE());
        _TimerText.text = "Time : " + countdownTimer.ToString();
    }

    public IEnumerator CountingIE()
    {
        while (canCount) 
        {
            yield return new WaitForSeconds(1f);
            countdownTimer -= 1f;
            _TimerText.text = "Time : " + countdownTimer.ToString();
            if (countdownTimer <= 0) 
            {
                canCount = false;
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
              //  player.transform.position = player.startPos;
               // countdownTimer = startTime;
                foreach (drag myObject in myobjects)
                {
                  //  myObject.transform.position = myObject.startPos;
                 //   myObject.transform.parent = null;
                    //myObject.GetComponent<SpriteRenderer>().enabled = false;
                    //myObject.GetComponent<BoxCollider2D>().enabled = false;
                    //myObject.sparkle.GetComponent<CircleCollider2D>().enabled = true;
                    //myObject.sparkle.GetComponent<SpriteRenderer>().enabled = true;
                }

                
              //  StartCounting();
                
            }
        }
        
    }


}
