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

public class Fade : MonoBehaviour {

	public Image image;
	Color color;
	float alphaValue;
	float Timer;
	public float fadeSpeed;
	public bool startFade;

	// Use this for initialization
	void Start () {
		Timer = 0.0f;
		alphaValue = 0.0f;
		if(!image)
			image = GetComponent<Image> ();
		color = image.color;
	}
	
	// Update is called once per frame
	void Update () {
		if (startFade)
			Timer += fadeSpeed * Time.deltaTime;
		else if (!startFade)
			Timer = 0;
		alphaValue = Timer;
		color.a = alphaValue;
		image.color = color;
	}
}
