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

public class LiveCounter : MonoBehaviour
{
	public GameManager manager;
	public Text text;
//	public Image lifeIconPrefab;
//
	public int lives;
//	public List<Image> lifeIcons = new List<Image>();

	private void Start()
	{
		UpdateLives();
	}

	private void Update()
	{
		if(manager.lives != lives)
		{
			UpdateLives();
		}
	}

	private void UpdateLives()
	{
		lives = Mathf.Max(0, manager.lives);

//		while(lives > lifeIcons.Count)
//		{
//			AddIcon();
//		}

//		int i = 0;
//		foreach(var image in GetComponentsInChildren<Image>())
//		{
//			image.enabled = i < lives;
//			i++;
//		}

		text.text = lives.ToString();
	}

//	private void AddIcon()
//	{
//		var newIcon = Instantiate(lifeIconPrefab);
//		newIcon.rectTransform.SetParent(transform);
//		newIcon.name = newIcon.name.Replace("(Clone)", (lifeIcons.Count+1).ToString());
//
//		newIcon.rectTransform.localScale = Vector3.one;
//		newIcon.rectTransform.localPosition = Vector3.zero;
//		newIcon.rectTransform.localRotation = Quaternion.identity;
//
//		lifeIcons.Add(newIcon);
//	}
}