HP Bar shows right percentage

This commit is contained in:
henriquenakashima 2020-09-17 23:14:34 -04:00
parent 6405508376
commit ea5108b0f5
4 changed files with 17 additions and 10 deletions

View file

@ -5,14 +5,19 @@ using UnityEngine.UI;
public class HeroInfoUI : MonoBehaviour
{
public GameObject target;
public BattleParticipant battleParticipant;
protected GameObject target;
protected BattleParticipant battleParticipant;
public Text nameText;
public Image healthBarBgImage;
public Image healthBarFgImage;
private Camera mainCamera;
public void Init(GameObject sprite, BattleParticipant battleParticipant) {
this.target = sprite;
this.battleParticipant = battleParticipant;
}
// Start is called before the first frame update
void Start()
{
@ -25,5 +30,9 @@ public class HeroInfoUI : MonoBehaviour
{
Vector3 targetPos = this.mainCamera.WorldToScreenPoint(target.transform.position);
transform.position = targetPos;
int hp = battleParticipant.getHP();
int maxHP = battleParticipant.getMaxHP();
healthBarFgImage.fillAmount = ((float) hp) / maxHP;
}
}