using System; using UnityEngine; using UnityEngine.UI; using Core; namespace Minigames.BirdPooper { /// /// Game over screen for Bird Pooper minigame. /// Displays when the player dies and allows restarting the level. /// 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. /// public void Show() { gameObject.SetActive(true); // Set canvas group for interaction if (canvasGroup != null) { canvasGroup.alpha = 1f; canvasGroup.interactable = true; canvasGroup.blocksRaycasts = true; } Debug.Log("[GameOverScreen] Game Over screen shown"); } /// /// 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); var progress = new Progress(p => Logging.Debug($"Loading progress: {p * 100:F0}%")); await SceneManagerService.Instance.ReloadCurrentScene(progress); } } }