using UnityEngine;
using System.Collections;

public class FadeColor : MonoBehaviour {

    public float speedTransition;

    SpriteRenderer[] spriteRenderers;
    public Color inicialColor; 
    Color[] startColor;
    public bool play  = false;
    void Start()
    {
        print(inicialColor); 
        spriteRenderers = GetComponentsInChildren<SpriteRenderer>();
        startColor = new Color[spriteRenderers.Length];

        for (int i = 0; i < spriteRenderers.Length; ++i)
        {
            startColor[i] = spriteRenderers[i].color;
            spriteRenderers[i].color = inicialColor;
        }
    }

    int i = 0;
    void FixedUpdate()
    {
        if (!play)
            return;

        if (i == spriteRenderers.Length)
            i = 0;

        spriteRenderers[i].color = Color.Lerp(spriteRenderers[i].color, startColor[i], speedTransition * Time.deltaTime);
        i++;
       
    }

    public void setInicialTransparentColor()
    { 
       inicialColor = new Color(1,1,1,0);
    }

}
