El teclado se accede con:
Keyboard.current
Antes de usarlo, conviene comprobar que exista:
if (Keyboard.current == null)
{
return;
}
if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
Saltar();
}
if (Keyboard.current.wKey.isPressed)
{
Debug.Log("W mantenida");
}
if (Keyboard.current.spaceKey.wasReleasedThisFrame)
{
Debug.Log("Soltaste espacio");
}
Vector2 input = Vector2.zero;
if (Keyboard.current != null)
{
input.x =
(Keyboard.current.dKey.isPressed ? 1f : 0f) -
(Keyboard.current.aKey.isPressed ? 1f : 0f);
input.y =
(Keyboard.current.wKey.isPressed ? 1f : 0f) -
(Keyboard.current.sKey.isPressed ? 1f : 0f);
}
Keyboard.current.escapeKey
Keyboard.current.enterKey
Keyboard.current.leftShiftKey
Keyboard.current.leftCtrlKey
Keyboard.current.eKey
Keyboard.current.rKey