unity-atoms/Examples/Assets/UniRx/UI/HealthBarUniRx.cs

22 lines
466 B
C#
Raw Normal View History

2020-03-02 02:26:06 +01:00
using UnityEngine;
using UnityEngine.UI;
using UniRx;
using UnityAtoms.BaseAtoms;
2019-10-09 00:13:33 +02:00
2020-03-02 02:26:06 +01:00
namespace UnityAtoms.Examples
{
public class HealthBarUniRx : MonoBehaviour
{
[SerializeField]
private IntVariable _health = null;
2019-10-09 00:13:33 +02:00
2020-03-02 02:26:06 +01:00
void Awake()
{
_health.ObserveChange().Subscribe(health =>
{
2020-03-02 18:42:19 +01:00
GetComponent<Image>().fillAmount = 1.0f * health / _health.InitialValue;
2020-03-02 02:26:06 +01:00
});
}
}
}