using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Fader : MonoBehaviour
{
    private Image fadePanel;

    private Color startColour;

    private bool fadingOut;

    private float fadeAmount;
    public float fadeSpeed;

	// Use this for initialization
	void Awake ()
    {
        fadePanel = GetComponent<Image>();
        startColour = fadePanel.color;
        fadingOut = false;
        fadeAmount = 1;
	}
	
	// Update is called once per frame
	void Update ()
    {
	    if (fadingOut && fadeAmount < 1)
            fadeAmount += Time.deltaTime * fadeSpeed;

        else if (!fadingOut && fadeAmount > 0)
            fadeAmount -= Time.deltaTime * fadeSpeed;

        fadePanel.color = new Color(startColour.r, startColour.g, startColour.b, fadeAmount);
    }

    public void setFadeOut(bool fadeOut)
    {
        if (fadeOut)
            fadingOut = true;
        else
            fadingOut = false;
    }

    public float GetFadeAmount()
    {
        return fadeAmount;
    }
}
