Update global input actions and rework player joining
This commit is contained in:
31
Assets/Scripts/AnimationPlayer.cs
Normal file
31
Assets/Scripts/AnimationPlayer.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class AnimationPlayer : MonoBehaviour
|
||||
{
|
||||
public enum AnimationState { Idle, Run, Jump };
|
||||
public AnimationState state;
|
||||
|
||||
public bool backwards;
|
||||
|
||||
public AnimationClip clip;
|
||||
|
||||
private Animator animator;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
animator.Play(clip.name);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
animator.SetInteger("state", (int)state);
|
||||
transform.localScale = new Vector3(Mathf.Sign(backwards ? -1 : 1) * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
|
||||
}
|
||||
|
||||
public void SetState(AnimationState state)
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AnimationPlayer.cs.meta
Normal file
2
Assets/Scripts/AnimationPlayer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e9d01bde449c4d0fa146e06804d6a03
|
||||
@@ -30,19 +30,6 @@ 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;
|
||||
@@ -68,11 +55,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user