【发布时间】:2023-01-30 14:29:07
【问题描述】:
我目前正在使用 Unity 开发平台视频游戏,但不确定如何使用新的输入系统检测何时按下了键。
我想知道,如果可能的话,您能否使用我当前的设置检测到何时按下键并将值分配给布尔值。
到目前为止,我有这段代码:
public void Jump(InputAction.CallbackContext context)
{
if (context.performed)
{
jump = true;
wasJumpLifted = true;
}
if (context.canceled)
{
wasJumpLifted = false;
}
else
{
wasJumpLifted = true;
}
}
这段代码的问题在于,如果您再次按下跳转键,它只会将 wasJumpLifted 设置为 true,因为如果我不按下跳转键,整个函数将不会被调用。
【问题讨论】: