Files
ClickRPG/Assets/Scripts/HealthBarUI.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2025-10-04 12:25:29 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2025-10-06 15:32:09 +01:00
using TMPro;
2025-10-04 12:25:29 +01:00
public class HealthBarUI : MonoBehaviour
{
2025-10-06 15:32:09 +01:00
public static HealthBarUI instance;
private void Awake() { instance = this; }
2025-10-04 12:25:29 +01:00
[SerializeField] private Image healthFill;
[SerializeField] private Character character;
2025-10-06 15:32:09 +01:00
[SerializeField] private TextMeshProUGUI nameText;
[SerializeField] private TextMeshProUGUI levelText;
[SerializeField] private TextMeshProUGUI attitudeTxt;
[SerializeField] private TextMeshProUGUI goldTxt;
2025-10-04 12:25:29 +01:00
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;
}
2025-10-06 15:32:09 +01:00
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;
}
2025-10-04 12:25:29 +01:00
}