HP Bar shows right percentage
This commit is contained in:
parent
6405508376
commit
ea5108b0f5
4 changed files with 17 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue