Working player + obstacle mvp
This commit is contained in:
101
Assets/Scripts/Minigames/BirdPooper/GameOverScreen.cs
Normal file
101
Assets/Scripts/Minigames/BirdPooper/GameOverScreen.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Core;
|
||||
using UI;
|
||||
|
||||
namespace Minigames.BirdPooper
|
||||
{
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
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<CanvasGroup>();
|
||||
if (canvasGroup == null)
|
||||
{
|
||||
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
// Hide by default
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from button
|
||||
if (dismissButton != null)
|
||||
{
|
||||
dismissButton.onClick.RemoveListener(OnDismissClicked);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the game over screen and pause the game.
|
||||
/// </summary>
|
||||
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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when dismiss button is clicked. Reloads the level.
|
||||
/// </summary>
|
||||
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<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.ReloadCurrentScene(progress, autoHideLoadingScreen: true, skipSave: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user