mixedcards/Assets/Battle/HeroInfoUI.cs
2020-09-17 23:14:34 -04:00

38 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HeroInfoUI : MonoBehaviour
{
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()
{
this.mainCamera = Camera.main;
this.nameText.text = this.battleParticipant.getDisplayName();
}
// Update is called once per frame
void Update()
{
Vector3 targetPos = this.mainCamera.WorldToScreenPoint(target.transform.position);
transform.position = targetPos;
int hp = battleParticipant.getHP();
int maxHP = battleParticipant.getMaxHP();
healthBarFgImage.fillAmount = ((float) hp) / maxHP;
}
}