using System; using UnityEngine; public class GameManager : MonoBehaviour { public Observer Balance = new(500f); public static GameManager Instance; public bool IsBuildMode = false; private Tower selectedTower; public float health = 0; public float startHealth = 100; public int CurrentNumEnemies = 0; public float Volume = 10f; /// /// First param: isBuildMode /// public static event Action OnUpdateUIRequested; public Tower SelectedTower { get { return selectedTower; } set { if (selectedTower != null) selectedTower.TowerSelected(false); selectedTower = value; if (selectedTower != null) selectedTower.TowerSelected(true); }} private void Awake() { if (Instance != null) { Destroy(gameObject); return; } Instance = this; health = startHealth; } public void Reset() { foreach (var go in GameObject.FindObjectsByType(FindObjectsSortMode.None)) { if (go != null && go != this.gameObject) Destroy(go); } Destroy(this.gameObject); } private void OnEnable() { MoneyManager.OnShopSelected += m_OnTowerShopSelected; TowerPlacementManager.OnTowerPlaced += m_finishBuildmode; } private void OnDisable() { MoneyManager.OnShopSelected -= m_OnTowerShopSelected; TowerPlacementManager.OnTowerPlaced -= m_finishBuildmode; } private void m_OnTowerShopSelected(TowerInfo info) { IsBuildMode = true; OnUpdateUIRequested?.Invoke(IsBuildMode); } private void m_finishBuildmode(TowerInfo info) { IsBuildMode = false; OnUpdateUIRequested?.Invoke(IsBuildMode); } }