using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class CsHPbar : MonoBehaviour {
private int maxHP;
private int currentHP;
// Update is called once per frame
void Update ()
{
if(transform.name == "Hero")
{
maxHP = transform.GetComponent<CsPlayer>().GetMaxHP();
currentHP = transform.GetComponent<CsPlayer>().GetHP();
}
else
{
maxHP = transform.GetComponent<CsMonster>().GetMaxHP();
currentHP = transform.GetComponent<CsMonster>().GetHP();
}
float value = (float)currentHP / maxHP;
Debug.Log(value);
var hpbar = transform.FindChild("Canvas").FindChild("Slider");
hpbar.GetComponent<Slider>().value = value;
}
}