using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField]
|
|
private PlayerList m_PlayerList;
|
|
|
|
[SerializeField]
|
|
private GameObject m_playerPrefab;
|
|
|
|
|
|
private Camera m_camera;
|
|
|
|
private void OnEnable()
|
|
{
|
|
m_PlayerList.OnPlayerJoin += OnPlayerJoin;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
m_PlayerList.OnPlayerJoin -= OnPlayerJoin;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
SetUpPlayers();
|
|
m_camera = Camera.main;
|
|
}
|
|
|
|
private void SetUpPlayers()
|
|
{
|
|
foreach (PlayerData data in m_PlayerList.AllPlayers)
|
|
{
|
|
SpawnPlayer(data);
|
|
}
|
|
}
|
|
|
|
|
|
private void SpawnPlayer(PlayerData data)
|
|
{
|
|
GameObject newPlayer = Instantiate(m_playerPrefab);
|
|
|
|
data.Input.SwitchCurrentActionMap("Gameplay");
|
|
|
|
foreach (InputBehaviour input in newPlayer.GetComponentsInChildren<InputBehaviour>())
|
|
input.Initialise(data);
|
|
|
|
newPlayer.GetComponentInChildren<PlayerVisuals>().Initalise(data);
|
|
|
|
newPlayer.transform.position += Vector3.ProjectOnPlane(Random.insideUnitSphere, Vector3.up);
|
|
}
|
|
|
|
private void OnPlayerJoin(object sender, PlayerData data)
|
|
{
|
|
SpawnPlayer(data);
|
|
}
|
|
|
|
}
|