using System; using UnityEngine; using UnityEngine.UI; using Core; using UI; namespace Minigames.BirdPooper { /// /// Game over screen for Bird Pooper minigame. /// Displays when the player dies and allows restarting the level. /// Uses unscaled time for UI updates (works when Time.timeScale = 0). /// public class GameOverScreen : MonoBehaviour { [Header("UI References")] [SerializeField] private Button dismissButton; [SerializeField] private CanvasGroup canvasGroup; private void Awake() { // Subscribe to button click if (dismissButton != null) { dismissButton.onClick.AddListener(OnDismissClicked); } else { Debug.LogError("[GameOverScreen] Dismiss button not assigned!"); } // Get or add CanvasGroup for fade effects if (canvasGroup == null) { canvasGroup = GetComponent(); if (canvasGroup == null) { canvasGroup = gameObject.AddComponent(); } } // Hide by default gameObject.SetActive(false); } private void OnDestroy() { // Unsubscribe from button if (dismissButton != null) { dismissButton.onClick.RemoveListener(OnDismissClicked); } } /// /// Show the game over screen and pause the game. /// public void Show() { gameObject.SetActive(true); // Set canvas group for interaction if (canvasGroup != null) { canvasGroup.alpha = 1f; canvasGroup.interactable = true; canvasGroup.blocksRaycasts = true; } // Pause the game (set timescale to 0) // PauseMenu uses unscaled time for tweens, so it will still work Time.timeScale = 0f; Debug.Log("[GameOverScreen] Game Over - Time.timeScale set to 0"); } /// /// Called when dismiss button is clicked. Reloads the level. /// private async void OnDismissClicked() { Debug.Log("[GameOverScreen] Dismiss button clicked - Reloading level"); // Hide this screen first if (canvasGroup != null) { canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; } gameObject.SetActive(false); // Reset time scale BEFORE reloading Time.timeScale = 1f; // Now reload the current scene with fresh state - skipSave=true prevents re-saving cleared data var progress = new Progress(p => Logging.Debug($"Loading progress: {p * 100:F0}%")); await SceneManagerService.Instance.ReloadCurrentScene(progress, autoHideLoadingScreen: true, skipSave: true); } } }