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

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5. [RequireComponent(typeof(PlayerInputManager))]
  6. public class PlayerManager : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private PlayerList m_connectedPlayers;
  10. private PlayerInputManager m_playerManager;
  11. private void OnEnable()
  12. {
  13. DontDestroyOnLoad(gameObject);
  14. m_playerManager = GetComponent<PlayerInputManager>();
  15. }
  16. public void OnPlayerJoined(UnityEngine.InputSystem.PlayerInput player)
  17. {
  18. GameObject newPlayer = player.gameObject;
  19. Debug.Log($"New Player Joined");
  20. PlayerData data = m_connectedPlayers.AddPlayer(player);
  21. newPlayer.GetComponent<PlayerDataHolder>().Initialise(data);
  22. newPlayer.transform.SetParent(transform, false);
  23. }
  24. public void AllowJoin(bool value)
  25. {
  26. if (value)
  27. m_playerManager.EnableJoining();
  28. else
  29. m_playerManager.DisableJoining();
  30. }
  31. }