29 lines
595 B
C#
29 lines
595 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class VrHealthView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image bar;
|
|
private Health health;
|
|
private bool initialized = false;
|
|
|
|
public void Initialize()
|
|
{
|
|
health = G.PlayerStateModel.PlayerHealthComponent;
|
|
health.HealthChanged += Refresh;
|
|
Refresh(-1);
|
|
initialized = true;
|
|
}
|
|
|
|
public void Refresh(float arg)
|
|
{
|
|
bar.fillAmount = health.HpPercent;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (!initialized) return;
|
|
health.HealthChanged -= Refresh;
|
|
}
|
|
}
|