diff --git a/Assets/Scripts/Manager/GameManager.cs b/Assets/Scripts/Manager/GameManager.cs index 6fa7cbb..dde420f 100644 --- a/Assets/Scripts/Manager/GameManager.cs +++ b/Assets/Scripts/Manager/GameManager.cs @@ -43,6 +43,16 @@ public class GameManager : MonoBehaviour 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; diff --git a/Assets/Scripts/UI/PlayerHealth.cs b/Assets/Scripts/UI/PlayerHealth.cs index 89ffe2d..e74b9a0 100644 --- a/Assets/Scripts/UI/PlayerHealth.cs +++ b/Assets/Scripts/UI/PlayerHealth.cs @@ -24,6 +24,7 @@ public class PlayerHealth : MonoBehaviour { gameOver.SetActive(true); yield return new WaitForSecondsRealtime(5f); + GameManager.Instance.Reset(); SceneManager.LoadScene(0); } diff --git a/Assets/Scripts/UI/SwitchScene.cs b/Assets/Scripts/UI/SwitchScene.cs index 5d93e37..30e4af5 100644 --- a/Assets/Scripts/UI/SwitchScene.cs +++ b/Assets/Scripts/UI/SwitchScene.cs @@ -7,6 +7,7 @@ public class SwitchScene : MonoBehaviour { public void SwitchToScene(string scene) { + GameManager.Instance.Reset(); SceneManager.LoadScene(scene); }