using UnityEngine; using TMPro; public class CashDisplay : MonoBehaviour { private TextMeshProUGUI cashText; private void Awake() { cashText = GetComponent(); } private void OnEnable() { ShowCash(); // Initial display GameConstants.OnCashChanged += OnCashChanged; // Subscribe to event } private void OnDisable() { GameConstants.OnCashChanged -= OnCashChanged; // Unsubscribe to avoid memory leaks } private void OnCashChanged(int newCash) { ShowCash(newCash); } private void ShowCash() { ShowCash(GameConstants.Cash); } private void ShowCash(int value) { Debug.Log("Current Cash: " + value); if (cashText != null) { cashText.text = "$" + value.ToString(); } } }