using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { // Static instance of GameManager for global access public static GameManager Instance { get; private set; } // Serialized field for game over UI reference [SerializeField] private GameObject gameOverUI; void Awake() { // Ensure there is only one instance of GameManager and it persists across scenes if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); // Optional: Keep GameManager between scene loads } else { Destroy(gameObject); // Destroy duplicate GameManager instances } } void Start() { // Ensure gameOverUI is initially inactive HideGameOver(); } public void GameOver() { if (gameOverUI != null) { gameOverUI.SetActive(true); } // Reset the player's gold before restarting the game ResetPlayerGold(); // Start the coroutine to restart the game after a delay StartCoroutine(RestartAfterDelay(3f)); // Adjust the delay as needed } private void ResetPlayerGold() { // Reset the player's gold to 0 if (EconomyManager.Instance != null) { EconomyManager.Instance.ResetGold(); } } public void Restart() { // Reload Scene 1 SceneManager.LoadScene("Scene1"); // Hide game over UI when restarting HideGameOver(); } public void HideGameOver() { if (gameOverUI != null) { gameOverUI.SetActive(false); } } private IEnumerator RestartAfterDelay(float delay) { yield return new WaitForSeconds(delay); // Wait for the specified delay // Restart the game Restart(); } }