unity-atoms/Examples/Assets/UniRx/UI/HealthBarUniRx.cs
2020-03-20 01:29:39 +01:00

25 lines
548 B
C#

using UnityEngine;
using UnityEngine.UI;
using UniRx;
using UnityAtoms.BaseAtoms;
namespace UnityAtoms.Examples
{
/// <summary>
/// Simple healthbar script using UniRx.
/// </summary>
public class HealthBarUniRx : MonoBehaviour
{
[SerializeField]
private IntVariable _health = null;
void Awake()
{
_health.ObserveChange().Subscribe(health =>
{
GetComponent<Image>().fillAmount = 1.0f * health / _health.InitialValue;
});
}
}
}