using UnityEngine; using TMPro; namespace CryingSnow.FarmingIsland { [RequireComponent(typeof(TextMeshProUGUI))] public class CoinDisplay : MonoBehaviour { // Reference to the TextMeshProUGUI component for displaying the coin amount. private TextMeshProUGUI displayText; void Awake() { // Get and cache the TextMeshProUGUI component attached to this GameObject. displayText = GetComponent(); } void Start() { // Subscribe to the coin change event in the IslandManager. // This ensures the display is updated whenever the player's coin amount changes. IslandManager.Instance.OnCoinChanged += UpdateDisplay; // Initialize the display with the current coin amount. UpdateDisplay(IslandManager.Instance.Coin); } /// /// Updates the displayed coin amount on the UI. /// /// The current coin amount. void UpdateDisplay(int coin) { // Format the coin amount and update the text display. displayText.text = coin.ToAbbreviatedString(); } } }