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

public class EndCondition : MonoBehaviour
{
    public static bool IsGameOver = false;

    public GameObject Player;
    public CanvasGroup GameOverOverlay;
    public float FadeInLength = 1;

    private IPlayer player;

    public void Start()
    {
        player = Player.GetComponent<IPlayer>();
    }

    public void Update()
    {
        if (player.Health <= 0 && !IsGameOver)
        {
            IsGameOver = true;
            StartCoroutine(FadeIn());
        }
    }

    private IEnumerator FadeIn()
    {
        float start = Time.time;
        while (GameOverOverlay.alpha < 1)
        {
            GameOverOverlay.alpha += (Time.time - start) / FadeInLength;
            yield return new WaitForEndOfFrame();
        }
    }
}
