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

public class VariateBackgroundColor : MonoBehaviour {
    public Color [] fadeColors; // Let user define color area.
    public float lerpTempoSpeed; // Strech tempo.

    private UnityEngine.UI.Image colorVariatedImage; // For speed and convenience.
    private int currentFadeIndex; // To which color to fade.
    private float lerpProgress; // For tight lerping.

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

    public void Update () {
        if (lerpProgress < 1f - StaticConstants.approximationFloat) {
            lerpProgress += DGA.control.clampedDeltaTime * lerpTempoSpeed * DGA.control.tempo;
            lerpProgress = Mathf.Clamp (lerpProgress, 0f, 1f);
            colorVariatedImage.color = Color.Lerp (colorVariatedImage.color, fadeColors [currentFadeIndex], lerpProgress);
        } else {
            currentFadeIndex = Mathf.FloorToInt (Mathf.Clamp (Random.Range (0f, fadeColors.Length), 0, fadeColors.Length - 1));
            lerpProgress = 0f;
        }
    }
}
