MiniGames/Assets/Scripts/SkyWalker/Skywalker_GameManager.cs

62 lines
1.5 KiB
C#

using UnityEngine;
public class Skywalker_GameManager : MonoBehaviour
{
public static Skywalker_GameManager Instance; // Singleton
[Header("UI References")]
public GameObject gameOverPanel;
[Header("Player Reference")]
public Skywalker_PlayerController player; // assign in inspector
private bool isGameOver = false;
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
if (gameOverPanel != null)
gameOverPanel.SetActive(false); // hide at start
}
/// <summary>
/// Call this to trigger jump + fall + game over UI.
/// </summary>
public void TriggerGameOver()
{
if (isGameOver) return;
isGameOver = true;
if (player != null)
{
// Force a jump first
player.ForceJumpForGameOver();
// Disable collider after short delay so the fall feels natural
Collider col = player.GetComponent<Collider>();
Rigidbody rb = player.GetComponent<Rigidbody>();
if (col != null && rb != null)
{
col.enabled = false;
rb.useGravity = true;
}
}
GameoverInvoker();
// Show panel
Debug.Log("GAME OVER!");
}
public void GameoverInvoker()
{
Invoke(nameof(GameoverPanelEnabler), 1.5f);
}
public void GameoverPanelEnabler()
{
if (gameOverPanel != null)
gameOverPanel.SetActive(true);
}
}