using System; using TMPro; using UnityEngine; public class GameManager : MonoBehaviour { #region GameManager private decimal _currentBalance = 1.00M; public decimal CurrentBalance { get => _currentBalance; set => _currentBalance = value; } [SerializeField] private TextMeshProUGUI BalanceText; #endregion // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { BalanceText.text = String.Format("$ {0:C2}", CurrentBalance.ToString()); } // Update is called once per frame void Update() { } public void AddToBalance(decimal amount) { CurrentBalance += amount; BalanceText.text = String.Format("$ {0:C2}", CurrentBalance.ToString()); } public void SubtractFromBalance(decimal amount) { if(CurrentBalance < amount) { Debug.Log("Not enough money"); return; } CurrentBalance -= amount; BalanceText.text = String.Format("$ {0:C2}", CurrentBalance.ToString()); } public bool CanAfford(decimal amount) { return CurrentBalance >= amount; } }