mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 00:58:59 -05:00
29 lines
677 B
C#
29 lines
677 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityAtoms.BaseAtoms;
|
|
|
|
namespace UnityAtoms.Examples
|
|
{
|
|
[AddComponentMenu("Unity Atoms/Examples/HealthBar")]
|
|
public class HealthBar : MonoBehaviour
|
|
{
|
|
public IntReference InitialHealth { get => _initialHealth; }
|
|
|
|
[SerializeField]
|
|
private IntReference _initialHealth = null;
|
|
|
|
[SerializeField]
|
|
private Image _image;
|
|
|
|
void Awake()
|
|
{
|
|
if (_image == null)
|
|
{
|
|
_image = GetComponent<Image>();
|
|
}
|
|
}
|
|
|
|
public void HealthChanged(int health) => _image.fillAmount = 1.0f * health / _initialHealth.Value;
|
|
}
|
|
}
|