using UnityEngine;
using Game;
using Music;
using Player;
using UnityEngine.InputSystem;
namespace Game
{
///
/// This class is used to create cards for players when they join the game.
///
public class PlayerCardCreator : MonoBehaviour
{
///
/// A single instance of this class that can be accessed from anywhere.
///
public static PlayerCardCreator Instance;
///
/// The template used to create new player cards.
///
public GameObject playerJoinCardPrefab;
///
/// Makes sure there is only one PlayerCardCreator in the game.
///
private void Awake()
{
// If this is the first instance, set it as the main one.
if (Instance == null)
{
Instance = this;
}
else
{
// If another instance already exists, remove this one.
Destroy(gameObject);
}
}
///
/// Creates a new player card and returns it.
///
/// The new player card, or nothing if it couldn't be created.
public PlayerJoinCard CreateCard()
{
try
{
// Make a new player card using the template.
GameObject card = Instantiate(playerJoinCardPrefab, transform);
// Return the player card so it can be used.
return card.GetComponent();
}
catch
{
// If something goes wrong, return nothing.
return null;
}
}
}
}