Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

45 lines
1015 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(PlayerInputManager))]
public class PlayerManager : MonoBehaviour
{
[SerializeField]
private PlayerList m_connectedPlayers;
private PlayerInputManager m_playerManager;
private void OnEnable()
{
DontDestroyOnLoad(gameObject);
m_playerManager = GetComponent<PlayerInputManager>();
}
public void OnPlayerJoined(UnityEngine.InputSystem.PlayerInput player)
{
GameObject newPlayer = player.gameObject;
Debug.Log($"New Player Joined");
PlayerData data = m_connectedPlayers.AddPlayer(player);
newPlayer.GetComponent<PlayerDataHolder>().Initialise(data);
newPlayer.transform.SetParent(transform, false);
}
public void AllowJoin(bool value)
{
if (value)
m_playerManager.EnableJoining();
else
m_playerManager.DisableJoining();
}
}