using Obvious.Soap; using UnityEngine; using UnityEngine.UI; public class UI_ActionCounter : MonoBehaviour { public FloatVariable actionCounter; public FloatVariable throwDistance; public FloatVariable maxCastPower; [SerializeField] private GameObject counterObject; [SerializeField] private Image barImage; public float fadeDuration = 0.2f; private void Start() { counterObject.SetActive(value: false); } private void Awake() { actionCounter.OnValueChanged += ActionCounterOnOnValueChanged; throwDistance.OnValueChanged += ThrowDistanceOnOnValueChanged; } private void OnDestroy() { actionCounter.OnValueChanged -= ActionCounterOnOnValueChanged; throwDistance.OnValueChanged -= ThrowDistanceOnOnValueChanged; } private void ThrowDistanceOnOnValueChanged(float obj) { barImage.fillAmount = obj / maxCastPower.Value; } private void ShowMetersText(bool show, bool instant = false) { if (show) { counterObject.SetActive(value: true); } else { counterObject.SetActive(value: false); } } private void ActionCounterOnOnValueChanged(float value) { ShowMetersText(value > 0f); } }