unity-atoms/Examples/Assets/UniRx/UI/HealthBarUniRx.cs
Adam Ramberg c3bc59259f More WIP
2020-03-02 02:26:06 +01:00

24 lines
534 B
C#

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