블랙잭 NPC 코인 및 AI Navigation 기능 추가
This commit is contained in:
73
Assets/02_Scripts/Managers/CoinManager.cs
Normal file
73
Assets/02_Scripts/Managers/CoinManager.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class CoinManager : MonoBehaviour
|
||||
{
|
||||
public static CoinManager Instance;
|
||||
|
||||
[Header("Coin Data")]
|
||||
public int currentCoins = 0;
|
||||
|
||||
[Header("UI")]
|
||||
public TMP_Text coinText;
|
||||
|
||||
[Header("Scene Setting")]
|
||||
public bool dontDestroyOnLoad = true;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
if (dontDestroyOnLoad)
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
UpdateCoinUI();
|
||||
}
|
||||
|
||||
public void AddCoin(int amount)
|
||||
{
|
||||
currentCoins += amount;
|
||||
UpdateCoinUI();
|
||||
|
||||
Debug.Log("Coin Added: " + amount + " / Total Coin: " + currentCoins);
|
||||
}
|
||||
|
||||
public bool SpendCoin(int amount)
|
||||
{
|
||||
if (currentCoins < amount)
|
||||
{
|
||||
Debug.Log("Not enough coins. Current: " + currentCoins + " / Need: " + amount);
|
||||
return false;
|
||||
}
|
||||
|
||||
currentCoins -= amount;
|
||||
UpdateCoinUI();
|
||||
|
||||
Debug.Log("Coin Spent: " + amount + " / Total Coin: " + currentCoins);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetCoinCount()
|
||||
{
|
||||
return currentCoins;
|
||||
}
|
||||
|
||||
void UpdateCoinUI()
|
||||
{
|
||||
if (coinText != null)
|
||||
{
|
||||
coinText.text = "Coin: " + currentCoins;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user