Reimplement player joining
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,9 +86,9 @@ public class PlayerMovement : MonoBehaviour
|
||||
animationPlayer.SetState(AnimationPlayer.AnimationState.Idle);
|
||||
}
|
||||
|
||||
if (body.linearVelocityX < 0)
|
||||
if (body.linearVelocityX < -0.1f)
|
||||
animationPlayer.backwards = true;
|
||||
else if (body.linearVelocityX > 0)
|
||||
else if (body.linearVelocityX > 0.1f)
|
||||
animationPlayer.backwards = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user