reset managers on death/home go

This commit is contained in:
Sveske Juice 2024-04-21 14:17:50 +02:00
parent 4baa667b4e
commit 504c967f45
3 changed files with 12 additions and 0 deletions

View File

@ -43,6 +43,16 @@ public class GameManager : MonoBehaviour
health = startHealth; health = startHealth;
} }
public void Reset()
{
foreach (var go in GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.None))
{
if (go != null && go != this.gameObject)
Destroy(go);
}
Destroy(this.gameObject);
}
private void OnEnable() private void OnEnable()
{ {
MoneyManager.OnShopSelected += m_OnTowerShopSelected; MoneyManager.OnShopSelected += m_OnTowerShopSelected;

View File

@ -24,6 +24,7 @@ public class PlayerHealth : MonoBehaviour
{ {
gameOver.SetActive(true); gameOver.SetActive(true);
yield return new WaitForSecondsRealtime(5f); yield return new WaitForSecondsRealtime(5f);
GameManager.Instance.Reset();
SceneManager.LoadScene(0); SceneManager.LoadScene(0);
} }

View File

@ -7,6 +7,7 @@ public class SwitchScene : MonoBehaviour
{ {
public void SwitchToScene(string scene) public void SwitchToScene(string scene)
{ {
GameManager.Instance.Reset();
SceneManager.LoadScene(scene); SceneManager.LoadScene(scene);
} }