以下示例展示如何在 Unity 中通过 Input.GetKeyDown 监听键盘的 W / S / A / D 四个按键,分别对应跳跃、翻滚、左跳和右跳的动作触发。
void InputKeyBoard()
{
if (Input.GetKeyDown (KeyCode.W)) {
//jump up
}
if (Input.GetKeyDown (KeyCode.S)) {
//roll
}
if (Input.GetKeyDown (KeyCode.A)) {
//jump left
}
if (Input.GetKeyDown (KeyCode.D)) {
//jump right
}
}