55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
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 expTxt;
|
|
[SerializeField] private TextMeshProUGUI levelTxt;
|
|
[SerializeField] private TextMeshProUGUI healthTxt;
|
|
[SerializeField] private TextMeshProUGUI damageTxt;
|
|
[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(int exp, int level, int damage, int health)
|
|
{
|
|
expTxt.text = "Exp: " + exp;
|
|
levelTxt.text = "Level: " + level;
|
|
damageTxt.text = "Health " + health;
|
|
goldTxt.text = "Damage " + damage;
|
|
}
|
|
public void UpdateGold(int gold)
|
|
{
|
|
goldTxt.text = "Gold: " + gold;
|
|
}
|
|
} |