You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
using System; |
|
using TMPro; |
|
|
|
using UnityEngine; |
|
|
|
public class GameManager : MonoBehaviour |
|
{ |
|
#region GameManager |
|
private float _currentBalance = 1.00f; |
|
public float 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(float amount) |
|
{ |
|
CurrentBalance += amount; |
|
BalanceText.text = String.Format("$ {0:C2}", CurrentBalance.ToString()); |
|
} |
|
|
|
public void SubtractFromBalance(float amount) |
|
{ |
|
if(CurrentBalance < amount) |
|
{ |
|
Debug.Log("Not enough money"); |
|
return; |
|
} |
|
CurrentBalance -= amount; |
|
BalanceText.text = String.Format("$ {0:C2}", CurrentBalance.ToString()); |
|
} |
|
|
|
public bool CanAfford(float amount) |
|
{ |
|
return CurrentBalance >= amount; |
|
} |
|
}
|
|
|