using System.Collections.Generic; using NUnit.Framework.Constraints; using UnityEngine; using UnityEngine.InputSystem; public class PlayerManager : MonoBehaviour { public static PlayerManager Instance; public List players; [SerializeField] private InputActionAsset playerActions; private Vector2 spawnPosition; private void Awake() { Init(); } private void Start() { GetComponent().onPlayerJoined += OnPlayerJoined; GetComponent().onPlayerLeft += OnPlayerLeft; } private void OnPlayerJoined(PlayerInput playerInput) { playerInput.transform.position = spawnPosition; players.Add(playerInput.gameObject); print("Player joined"); } private void OnPlayerLeft(PlayerInput playerInput) { Destroy(playerInput.gameObject); players.Remove(playerInput.gameObject); print("Player left"); } private void Init() { if (Instance == null) { Instance = this; } else { print("A PlayerManager already exists."); Destroy(this.gameObject); } spawnPosition = transform.position; } }