Untitled

mail@pastecode.io avatar
unknown
csharp
a month ago
658 B
6
Indexable
Never
    public class ResourceUI : MonoBehaviour
    {
        [SerializeField] private TMP_Text resourceText;
        [SerializeField] private ResourceSo resourceData;
        
        private void Start()
        {
            SetResourceText(resourceData.Current);
        }

        private void OnEnable()
        {
            resourceData.OnValueChanged += SetResourceText;
        }
        
        private void OnDisable()
        {
            resourceData.OnValueChanged -= SetResourceText;
        }
        
        private void SetResourceText(int t)
        {
            resourceText.text = t.ToCurrency();
        }
    }