MiniGames/Assets/Scripts/ClawGrab/GameOverPanelController.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2025-09-06 00:08:22 +05:00
using System.Linq;
using System.Text;
using TMPro;
using UnityEngine;
public class GameOverPanelController : MonoBehaviour
{
[Header("References")]
public GameObject panelRoot; // The panel GameObject inside your Screen Space Canvas
public TextMeshProUGUI titleText; // Top text -> will be set to "GAME OVER"
public TextMeshProUGUI finalScoreText; // Shows final score
public TextMeshProUGUI breakdownText; // Multiline text listing collected items
[Header("Options")]
public string gameOverTitle = "GAME OVER";
void Awake()
{
Hide(); // start hidden by default
}
public void ShowGameOver(ClawScoreManager scoreMgr)
{
if (panelRoot != null) panelRoot.SetActive(true);
if (titleText != null)
titleText.text = gameOverTitle;
if (finalScoreText != null && scoreMgr != null)
finalScoreText.text = $"Final Score: {scoreMgr.CurrentScore}";
if (breakdownText != null && scoreMgr != null)
{
// Build a simple list of counts > 0
var sb = new StringBuilder();
var counts = scoreMgr.CollectedCounts;
// sort by name for a stable display
foreach (var kv in counts.OrderBy(kv => kv.Key.ToString()))
{
if (kv.Value > 0)
sb.AppendLine($"{kv.Key}: {kv.Value}");
}
// If nothing was collected, show a friendly message
breakdownText.text = sb.Length > 0 ? sb.ToString().TrimEnd() : "No items collected.";
}
}
public void Hide()
{
if (panelRoot != null)
panelRoot.SetActive(false);
}
}