85 lines
1.8 KiB
C#
85 lines
1.8 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.Events;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager instance { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
[Header("Player Stats")]
|
|
public int health;
|
|
public int money;
|
|
|
|
[Header("Components")]
|
|
public TextMeshProUGUI healthAndMoneyText;
|
|
public EnemyPath enemyPath;
|
|
|
|
[Header("Events")]
|
|
public UnityEvent onEnemyDestroyed;
|
|
public UnityEvent onMoneyChanged;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
void UpdateHealthAndMoneyText()
|
|
{
|
|
//healthAndMoneyText.text = $"Health: {health}\nMoney: {money}G";
|
|
}
|
|
public void AddMoney(int amount)
|
|
{
|
|
money += amount;
|
|
UpdateHealthAndMoneyText();
|
|
onMoneyChanged.Invoke();
|
|
}
|
|
public void TakeMoney (int amount)
|
|
{
|
|
money -= amount;
|
|
UpdateHealthAndMoneyText();
|
|
onMoneyChanged.Invoke();
|
|
}
|
|
public void TakeDamage (int damage)
|
|
{
|
|
health -= damage;
|
|
UpdateHealthAndMoneyText();
|
|
if (health <= 0)
|
|
{
|
|
// Handle game over logic here
|
|
GameOver();
|
|
}
|
|
}
|
|
void GameOver()
|
|
{
|
|
Debug.Log("Game Over!");
|
|
// Additional game over handling can be added here
|
|
}
|
|
void WinGame()
|
|
{
|
|
Debug.Log("You Win!");
|
|
// Additional win handling can be added here
|
|
}
|
|
public void OnEnemyDestroyed()
|
|
{
|
|
|
|
}
|
|
}
|