26 lines
552 B
C#
26 lines
552 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
[RequireComponent(typeof(Image))]
|
|
public class HealthBarUpdater : MonoBehaviour
|
|
{
|
|
private Health _health;
|
|
private Image _bar;
|
|
public void Init(Health health)
|
|
{
|
|
_bar = GetComponent<Image>();
|
|
_health = health;
|
|
_health.HealthChanged += UpdateBar;
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if( _health != null )
|
|
_health.HealthChanged -= UpdateBar;
|
|
}
|
|
|
|
private void UpdateBar(float obj)
|
|
{
|
|
_bar.fillAmount = _health.HpPercent;
|
|
}
|
|
}
|