using UnityEngine;
using System.Collections;

public class Lifes : MonoBehaviour {
    public float recoverTime;
    public GameObject[] useSprites;

    private int uses;
	// Use this for initialization
	void Start () {
        uses = useSprites.Length;
        StartCoroutine(waitAndAdd());
    }
    IEnumerator waitAndAdd()
    {
        yield return new WaitForSeconds(recoverTime);
        if (uses < useSprites.Length)
        {
            uses = uses + 1;
            updateSprites();
        }
        StartCoroutine(waitAndAdd());
    }

    public int getUses()
    {
        return uses;
    }
    public void useRing()
    {
        uses -= 1;
        updateSprites();
    }
    private void updateSprites()
    {
        for (int i = 0; i < useSprites.Length; i++)
        {
            if (i <= uses - 1)
            {
                useSprites[i].GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
            } else
            {
                useSprites[i].GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
            }
        }
    }
}
