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

public class CountdownBeforeStart : MonoBehaviour
{
    public float startAt;
    private float cpt;
    public GameObject trois, deux, un, gogogo;
    // Start is called before the first frame update
    void Start()
    {
        cpt = 0f;
        trois.SetActive(false);
        deux.SetActive(false);
        un.SetActive(false);
        gogogo.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if (startAt == -1f || cpt > startAt + 1.5f) return;
        cpt += Time.deltaTime;

        if (cpt > startAt - 3 && cpt < startAt - 2)
        {
            trois.SetActive(true);
            trois.transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 2f, cpt - (startAt - 3));
        }
        else if (cpt > startAt - 2 && cpt < startAt - 1)
        {
            trois.SetActive(false);
            deux.SetActive(true);
            deux.transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 2f, cpt - (startAt - 2));
        }
        else if (cpt > startAt - 1 && cpt < startAt)
        {
            deux.SetActive(false);
            un.SetActive(true);
            un.transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 2f, cpt - (startAt - 1));
        }
        else if (cpt > startAt && cpt < startAt + 1)
        {
            un.SetActive(false);
            gogogo.SetActive(true);
            gogogo.transform.localScale = Vector3.Lerp(Vector3.one * 2f, Vector3.zero, cpt - startAt);
        }
        else if (cpt > startAt + 1)
        {
            gogogo.SetActive(false);
            foreach(var player in FindObjectsOfType<SausageGamePlay>())
            {
                Debug.Log("GO");
                player.go = true;
            }            
        }

    }
}
