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.
 
 
 
 

62 lines
1.3 KiB

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);
}
}