feat(PlayerMovement): Enhance input action handling for backward compatibility
This commit is contained in:
@@ -20,7 +20,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
[Header("Camera/Head")]
|
||||
public Transform CameraTransform;
|
||||
public float MaxLookAngle = 90f;
|
||||
|
||||
|
||||
private float m_verticalRotation = 0f;
|
||||
|
||||
public float WalkSpeed = 10;
|
||||
@@ -50,8 +50,9 @@ public class PlayerMovement : MonoBehaviour
|
||||
m_moveAction = map.FindAction("Move");
|
||||
m_lookAction = map.FindAction("Look");
|
||||
m_jumpAction = map.FindAction("Jump");
|
||||
m_throwAction = map.FindAction("Throw");
|
||||
m_pickupAction = map.FindAction("Pickup");
|
||||
// Support both old and new action names without breaking the scene setup.
|
||||
m_throwAction = map.FindAction("Throw") ?? map.FindAction("Attack");
|
||||
m_pickupAction = map.FindAction("Pickup") ?? map.FindAction("Interact");
|
||||
|
||||
m_rigidbody = GetComponent<Rigidbody>();
|
||||
animator = GetComponent<Animator>();
|
||||
@@ -73,23 +74,23 @@ public class PlayerMovement : MonoBehaviour
|
||||
m_headInitialLocalPos = Head.localPosition;
|
||||
m_headInitialLocalRot = Head.localRotation;
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
m_moveAmt = m_moveAction.ReadValue<Vector2>();
|
||||
m_lookAmt = m_lookAction.ReadValue<Vector2>();
|
||||
m_moveAmt = m_moveAction != null ? m_moveAction.ReadValue<Vector2>() : Vector2.zero;
|
||||
m_lookAmt = m_lookAction != null ? m_lookAction.ReadValue<Vector2>() : Vector2.zero;
|
||||
|
||||
if (m_jumpAction.WasPressedThisFrame())
|
||||
if (m_jumpAction != null && m_jumpAction.WasPressedThisFrame())
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
|
||||
if (m_throwAction.WasPressedThisFrame())
|
||||
if (m_throwAction != null && m_throwAction.WasPressedThisFrame())
|
||||
{
|
||||
ThrowHead();
|
||||
}
|
||||
|
||||
if (m_pickupAction.WasPressedThisFrame())
|
||||
if (m_pickupAction != null && (m_pickupAction.WasPressedThisFrame() || m_pickupAction.WasPerformedThisFrame()))
|
||||
{
|
||||
TryPickupHead();
|
||||
}
|
||||
@@ -141,7 +142,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
// HEAD ROTATION ON GROUND
|
||||
float headRotation = m_lookAmt.x * RotateSpeed * Time.deltaTime;
|
||||
Head.Rotate(0, headRotation, 0);
|
||||
|
||||
|
||||
// Add vertical camera rotation when head is on ground
|
||||
if (CameraTransform != null)
|
||||
{
|
||||
@@ -165,7 +166,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
return;
|
||||
|
||||
animator.SetTrigger("Throw");
|
||||
|
||||
|
||||
m_isHeadThrown = true;
|
||||
|
||||
Head.SetParent(null);
|
||||
|
||||
Reference in New Issue
Block a user