Reimplement player joining

This commit is contained in:
RochesterX
2025-01-17 09:40:48 -05:00
parent 1315bdb7dc
commit 4623583ffd
7 changed files with 681 additions and 145 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using NUnit.Framework.Constraints;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -8,6 +9,11 @@ public class PlayerManager : MonoBehaviour
public List<GameObject> players;
[SerializeField] private Vector2 spawnPosition;
[SerializeField] private InputActionAsset playerActions;
[Header("Debug")]
[SerializeField] private InputActionAsset player2Actions;
private PlayerCameraMovement playerCamera;
@@ -24,6 +30,19 @@ public class PlayerManager : MonoBehaviour
playerCamera = FindFirstObjectByType<PlayerCameraMovement>();
}
private void Update()
{
if (InputSystem.actions.FindAction("Join Player").WasPressedThisFrame())
{
JoinPlayer(playerActions);
}
if (Keyboard.current.periodKey.wasPressedThisFrame)
{
JoinPlayer(player2Actions);
}
}
private void OnPlayerJoined(PlayerInput playerInput)
{
playerInput.transform.position = spawnPosition;
@@ -49,4 +68,11 @@ public class PlayerManager : MonoBehaviour
print("A PlayerManager already exists.");
}
}
private void JoinPlayer(InputActionAsset actions)
{
PlayerInput player = GetComponent<PlayerInputManager>().JoinPlayer(-1, -1, null, Keyboard.current);
print(player == null);
player.actions = actions;
}
}