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

public class GameOverControl : MonoBehaviour {
    public float fadeSpeed = 5f; // How quickly to fade out.

    private UnityEngine.UI.Image gameOverImage; // For speed and convenience.
    private float fadeProgress = 0f; // For tight control.
    private bool fadeIn; // Whether to fade in.

    public void Awake () {
        gameOverImage = transform.GetComponent <UnityEngine.UI.Image> ();
    }

    public void StartFade () {
        fadeIn = true;
    }

    public void Update () {
        if (fadeIn) {
            if (fadeProgress < 1f - StaticConstants.approximationFloat) {
                fadeProgress += DGA.control.clampedDeltaTime * fadeSpeed;
                fadeProgress = Mathf.Clamp (fadeProgress, 0f, 1f);

                Color fadeColor = new Color (gameOverImage.color.r, gameOverImage.color.g, gameOverImage.color.b, fadeProgress);
                gameOverImage.color = fadeColor;
            }
        }
    }
}
