using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerControl : MonoBehaviour
{
// 基本定义
private Rigidbody2D rb;
private Vector2 moveInput;
// 基本属性
float basespeed = 3f;
// 键盘状态
bool sprinting;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
public void OnMove(InputValue direction)
{
moveInput = direction.Get<Vector2>();
}
public void OnSprint(InputValue value)
{
Debug.Log(value.isPressed);
sprinting = value.isPressed;
}
private void FixedUpdate()
{
if (sprinting == false)
{
rb.linearVelocity = moveInput * basespeed;
}
else
{
rb.linearVelocity = moveInput * basespeed * 2;
}
}
}
评论 (0)