Files
Shopping_UnityVR/Assets/02_Scripts/Data/Player/PlayerWallet.cs
2026-05-11 13:12:48 +09:00

44 lines
1.0 KiB
C#

using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace VRShopping.Player
{
public class PlayerWallet : MonoBehaviour
{
// 예산 (Inspector에서 초기값 설정)
[SerializeField, Min(0), FormerlySerializedAs("Budget")]
private int _budget;
// UI 갱신용 이벤트
public event Action<int> OnBudgetChanged;
public int Budget => _budget;
private void Start()
{
OnBudgetChanged?.Invoke(_budget);
}
public bool PayMoney(int cost)
{
//예산이 비용보다 많을시
if (_budget >= cost)
{
_budget -= cost;
OnBudgetChanged?.Invoke(_budget);
return true;
}
//예산 부족
return false;
}
// 미션 생성 시점에 예산 덮어쓰기
public void SetBudget(int budget)
{
_budget = Mathf.Max(0, budget);
OnBudgetChanged?.Invoke(_budget);
}
}
}