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

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

    private UnityEngine.UI.Image titleImage; // For speed and convenience.
    private float fadeProgress = 1f; // For tight control.
    private bool fadeOut; // Whether to fade out.

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

    public void Update () {
        if (Input.GetButtonDown ("Submit")) {
            fadeOut = true;
            DGA.control.gameStarted = true;
        } if (fadeOut) {
            if (fadeProgress > StaticConstants.approximationFloat) {
                fadeProgress -= DGA.control.clampedDeltaTime * fadeSpeed;
                fadeProgress = Mathf.Clamp (fadeProgress, 0f, 1f);

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