using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class HealthBarUI : MonoBehaviour { public static HealthBarUI instance; private void Awake() { instance = this; } [SerializeField] private Image healthFill; [SerializeField] private Character character; [SerializeField] private TextMeshProUGUI nameText; [SerializeField] private TextMeshProUGUI levelText; [SerializeField] private TextMeshProUGUI attitudeTxt; [SerializeField] private TextMeshProUGUI goldTxt; void OnEnable () { character.onTakeDamage += UpdateHealthBar; } void OnDisable () { character.onTakeDamage -= UpdateHealthBar; } void Start () { UpdateHealthBar(); } void Update () { transform.rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position); } void UpdateHealthBar () { healthFill.fillAmount = (float)character.CurHp / (float)character.MaxHp; } public void UpdateInfoPanel(string name, int level, Character.Attitude attitude) { nameText.text = "Name: " + name; levelText.text = "Level: " + level; attitudeTxt.text = "Attitude " + attitude; } public void UpdateGold(int gold) { goldTxt.text = "Gold: " + gold; } }