Project Restructure (PLEASE UPDATE AFTER COMMIT)
This commit is contained in:
52
Assets/Scripts/PlayerManager.cs
Normal file
52
Assets/Scripts/PlayerManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
public static PlayerManager Instance;
|
||||
|
||||
public List<GameObject> players;
|
||||
[SerializeField] private Vector2 spawnPosition;
|
||||
|
||||
private PlayerCameraMovement playerCamera;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GetComponent<PlayerInputManager>().onPlayerJoined += OnPlayerJoined;
|
||||
GetComponent<PlayerInputManager>().onPlayerLeft += OnPlayerLeft;
|
||||
|
||||
playerCamera = FindFirstObjectByType<PlayerCameraMovement>();
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user