En proyectos modernos de Unity conviene usar el Input System para teclado, mouse y gamepads.
El paquete puede instalarse y configurarse desde el Package Manager.
Necesita:
using UnityEngine.InputSystem;
Teclado:
if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
Saltar();
}
Mouse:
if (Mouse.current.leftButton.wasPressedThisFrame)
{
Disparar();
}
Vector2 movimiento = Vector2.zero;
if (Keyboard.current != null)
{
movimiento.x =
(Keyboard.current.dKey.isPressed ? 1f : 0f) -
(Keyboard.current.aKey.isPressed ? 1f : 0f);
movimiento.y =
(Keyboard.current.wKey.isPressed ? 1f : 0f) -
(Keyboard.current.sKey.isPressed ? 1f : 0f);
}
Para proyectos medianos o grandes es mejor usar Input Actions.
Conceptos principales: