using UnityEngine;
using System.Collections;

public class Healt : MonoBehaviour {

    [SerializeField]
    GameObject HealtObj;

    GameObject[] HealtSet = new GameObject[10];

    int MaxHP = 0;
    int HP = 0;
	// HPのセッティング
	public void Startini (int hp) {
        MaxHP = hp;
        if (MaxHP > 10) {
            Debug.Log("HPは10を超えて指定できません");
            MaxHP = 10;
        }
        HP = MaxHP;
        for (int i = 0; i < MaxHP; i++) {
            HealtSet[i] = Instantiate(HealtObj) as GameObject;
            HealtSet[i].transform.position = new Vector3(i * 2 + transform.position.x, transform.position.y, transform.position.z);
        }
	}
	
	// 指定されたHPに変える
	public void HPUpdate (int hp) {
        HP = Mathf.Clamp(hp, 0, MaxHP);
        for(int i = 0; i < MaxHP; i++) {
            if (i < HP) {
                HealtSet[i].GetComponent<SpriteRenderer>().color = Color.white;
            }else {
                HealtSet[i].GetComponent<SpriteRenderer>().color = Color.black;
            }
        }
	}
}
