Files
YachtDice/Assets/Scripts/Economy/CurrencyBank.cs
T
2026-03-02 12:49:12 +07:00

46 lines
1020 B
C#

using System;
using UnityEngine;
namespace YachtDice.Economy
{
public class CurrencyBank : MonoBehaviour
{
[SerializeField] private int startingBalance = 500;
public int Balance { get; private set; }
public event Action<int> OnBalanceChanged;
private void Awake()
{
Balance = startingBalance;
}
public void Add(int amount)
{
if (amount <= 0) return;
Balance += amount;
OnBalanceChanged?.Invoke(Balance);
}
public bool Spend(int amount)
{
if (amount <= 0) return false;
if (Balance < amount) return false;
Balance -= amount;
OnBalanceChanged?.Invoke(Balance);
return true;
}
public bool CanAfford(int amount) => Balance >= amount;
public void SetBalance(int value)
{
Balance = Mathf.Max(0, value);
OnBalanceChanged?.Invoke(Balance);
}
}
}