InputAction
- Single input definition (jump, move, shoot)
- Can have multiple device bindings
- Has specific value type (Button/Value/Vector2)
- Processes input through interactions
- Can modify input through processors
Setup
- [SerializeField] InputActionAsset asset - Reference in Inspector
- [SerializeField] PlayerInput playerInput - Add component
- InputActionMap gameplayMap - Reference in script
- InputAction moveAction - Individual action reference
Action Map Setup
- Create: new InputActionMap("GameplayMap")
- Enable: gameplayMap.Enable()
- Disable: gameplayMap.Disable()
- Get Action: gameplayMap.FindAction("move")
InputAction Properties
- Type: Button/Value/Vector2
- Control Scheme: Device grouping
- Interactions: Tap/Hold/Press
- Processors: Normalize/Invert/Scale
InputAction Phases
- Performed: Input recognized
Binding Syntax
- Single Key: "<Keyboard>/space"
- Modifiers: "<Keyboard>/leftShift+w"
- Mouse: "<Mouse>/position", "<Mouse>/scroll/y"
- Gamepad: "<Gamepad>/buttonSouth", "<Gamepad>/rightTrigger"
- Touch: "<Touchscreen>/touch*/position"
- VR: "<XRController>{RightHand}/trigger"
Input Reading Methods
- moveAction.ReadValue<Vector2>()
- shootAction.ReadValue<float>()
- jumpAction.WasPressedThisFrame()
- jumpAction.WasReleasedThisFrame()
Event System Methods
- moveAction.performed += OnMove
- moveAction.started += OnMoveStart
- moveAction.canceled += OnMoveEnd
- InputSystem.onDeviceChange += OnDeviceChange
- playerInput.onActionTriggered += OnAction
Required Function Implementations
- Awake(): Cache action references
- OnEnable(): Subscribe to events
- OnDisable(): Unsubscribe from events
- OnMove(CallbackContext): Handle input
Runtime Checks Required