通过点击 shift 保持移动和冲刺

holding movement and dashing by tapping shift

我正在尝试让我的角色在我点击 shift 时向其当前移动的方向冲刺。现在我必须按住shift然后点击我想冲刺的方向。

我试过调高顺序,我试过更改代码以使用双击冲刺。到目前为止运气不好

public class Dash : MonoBehaviour
{

private Rigidbody rb;

public float dashSpeed;
private float dashTime;
public float startDashTime;
private int direction;


void Update()
{
    //dash
    if (direction == 0)
    {
        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.A))
        {
            direction = 1;
        }
        else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.D))
        {
            direction = 2;
        }
        else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.W))
        {
            direction = 3;
        }
        else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.S))
        {
            direction = 4;
        }

我想让角色向左冲刺。我希望能够按住 "A" 键向那个方向扫射,然后点击 "Shift" 进行短划。

如果我按住 "A" 我会朝这个方向扫射但是 "Shift" 什么都不做。如果我按住 "Shift" 然后点按 "A" 字符会出现我期望的破折号。

而不是:

if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.A))

尝试:

if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKey(KeyCode.A))

Input.GetKeyDown olnly returns true 在第一帧按下键,而 Input.GetKey returns true 每一帧你都是拿着钥匙