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

public class SymbolManager : SceneSingleton<SymbolManager> {

	public List<SpriteRenderer> symbolRenderers;

	const float TIME_TO_SHOW = 0.35f;
	const float DELAY = 0.25f;
	const float TIME_TO_HIDE = 0.35f;

	float startingAlpha = 0.2f;

	void Start()
	{
		//Invoke("EnableSymbolRenderer", 2f);
		//EnableSymbolRenderer(0);
	}

	// Update is called once per frame
	public void EnableSymbolRenderer (int index) {
	
		StartCoroutine(StartFadeIn(symbolRenderers[index]));

	}

	IEnumerator StartFadeIn(SpriteRenderer spriteRenderer)
	{
		Color spriteRendererColour  = spriteRenderer.color;
		spriteRendererColour.a = startingAlpha;
		spriteRenderer.color = spriteRendererColour;

		float timer = 0;

		while(timer <= TIME_TO_SHOW)
		{
			timer += Time.deltaTime;
			float zeroTo1 = timer / TIME_TO_SHOW;
			Debug.Log(zeroTo1);
			spriteRenderer.color = Color.Lerp(spriteRendererColour, Color.white, zeroTo1 );
			yield return 0;
		}

		/*timer = 0;

		while(timer <= DELAY)
		{
			timer += Time.deltaTime;
			yield return 0;
		}*/

		timer = TIME_TO_HIDE;

		while(timer > 0)
		{
			timer -= Time.deltaTime;
			float zeroTo1 = timer / TIME_TO_HIDE;
			Debug.Log(zeroTo1);
			spriteRenderer.color = Color.Lerp(spriteRendererColour, Color.white, timer / TIME_TO_HIDE );
			yield return 0;
		}
	}

	/*IEnumerator StartFadeIn(SpriteRenderer spriteRenderer)
	{
		Color spriteRendererColour  = spriteRenderer.color;
		spriteRendererColour.a = 0;
		spriteRenderer.color = spriteRendererColour;

		while(true)
		{
			spriteRendererColour.a += (1 * Time.deltaTime);
			spriteRenderer.color = spriteRendererColour;
			yield return new WaitForSeconds(0.1f);
		}
	}*/
}
