using System.Collections.Generic;
using TMPro;
using UnityEngine;
using Game;
using Music;
using Player;
namespace Game
{
///
/// Manages the win screen display for the game.
/// Displays the winning player's information and triggers the win screen animation.
///
public class WinScreen : MonoBehaviour
{
///
/// A singleton instance of the class.
/// Ensures only one instance of the WinScreen exists at a time.
///
public static WinScreen Instance;
///
/// A list of text elements used to display player information on the win screen.
///
public List playerTexts;
///
/// Ensures only one instance of the WinScreen exists.
/// Destroys duplicate instances if they are created.
///
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(this.gameObject);
}
}
///
/// Displays the win screen for the specified player.
/// Updates the text and color of the win screen to reflect the winning player.
///
/// The number of the winning player (1-based index).
public void ShowWinScreen(int player)
{
// Validate the player index
if (player - 1 < 0 || player - 1 >= GameManager.playerColors.Count)
{
return;
}
// Update the text and color for each player text element
foreach (TextMeshProUGUI playerText in playerTexts)
{
playerText.text = "Player " + player;
if (playerText.color != Color.black)
{
playerText.color = GameManager.playerColors[player - 1];
}
}
// Trigger the win screen animation
Animator animator = GetComponent();
if (animator == null)
{
return;
}
animator.SetTrigger("win");
}
}
}