Ejemplo simple usando Input Actions para mover un jugador.
Crear:
Action Map: Player
Move
- Action Type: Value
- Control Type: Vector2
- WASD: 2D Vector Composite
- Gamepad: Left Stick
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
[SerializeField]
private InputActionReference moveAction;
[SerializeField]
private float velocidad = 5f;
void Update()
{
Vector2 input = moveAction.action.ReadValue<Vector2>();
Vector3 direccion = new Vector3(
input.x,
0f,
input.y
);
transform.position +=
direccion * velocidad * Time.deltaTime;
}
}
Agregar una Action:
Jump
- Action Type: Button
- Space
- Gamepad South
Script:
[SerializeField]
private InputActionReference jumpAction;
void Update()
{
if (jumpAction.action.WasPressedThisFrame())
{
Saltar();
}
}
El código pregunta:
¿Se ejecutó Move?
¿Se ejecutó Jump?
No pregunta:
¿W?
¿Space?
¿Botón A?
Los bindings se encargan de traducir los dispositivos físicos a acciones del juego.