Loading...
Loading...
Wire player input in Unity 6 with the Input System package: Input Actions, action maps, the PlayerInput component, and reading values via callbacks or polling. Use when the project has a .inputactions asset or com.unity.inputsystem, or when the user mentions the Unity Input System, InputAction, action maps, PlayerInput, control schemes, or rebinding.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills unity-input-systemcom.unity.inputsystemInput.GetAxisInput.GetKey.inputactionsPlayerInputVector2Packages/manifest.jsoncom.unity.inputsystem*.inputactionsinput-systemsunity-physicsunity-csharp-scriptingInput System Package (New)BothBothInput.GetAxis.inputactionsGameplayMoveJumpFirePlayerInputInputActionReferenceInputActionAssetEnable()PlayerInput.Enable()PlayerInputusing UnityEngine;
using UnityEngine.InputSystem;
// PlayerInput (Behavior = Send Messages) calls On<ActionName>(InputValue) by name.
public class PlayerInputReceiver : MonoBehaviour
{
private Vector2 _move;
private void OnMove(InputValue value) => _move = value.Get<Vector2>(); // Move action
private void OnJump(InputValue value) { if (value.isPressed) Jump(); } // Button action
private void Update() { /* drive movement from _move */ }
private void Jump() { }
}using UnityEngine;
using UnityEngine.InputSystem;
public class DirectMover : MonoBehaviour
{
[SerializeField] private InputActionReference moveAction; // assign the Move action
private void OnEnable() => moveAction.action.Enable(); // REQUIRED or it reads zero
private void OnDisable() => moveAction.action.Disable();
private void Update()
{
Vector2 move = moveAction.action.ReadValue<Vector2>(); // continuous value
transform.Translate(new Vector3(move.x, 0, move.y) * (5f * Time.deltaTime));
}
}[SerializeField] private InputActionAsset actions;
private void OnEnable()
{
actions.FindAction("Gameplay/Fire").performed += OnFire; // edge event: fires once
actions.FindActionMap("Gameplay").Enable();
}
private void OnDisable() => actions.FindAction("Gameplay/Fire").performed -= OnFire;
private void OnFire(InputAction.CallbackContext ctx) => Shoot(); // ctx.ReadValue<T>() if needed
private void OpenPauseMenu() // change context, don't sprinkle if-checks
{
actions.FindActionMap("Gameplay").Disable();
actions.FindActionMap("UI").Enable();
}
private void Shoot() { }Input Manager (Old)Enable()PlayerInputInputActionInvalidOperationExceptionInput.GetAxisInput.GetKeyNewBothReadValueperformedWasPressedThisFrame()ReadValueSend MessagesPlayerInputBroadcast Messages-=OnDisableOnEnablePerformInteractiveRebindingPlayerInputManagerreferences/rebinding.mdhttps://docs.unity3d.com/Manual/com.unity.inputsystem.htmlinput-systemsunity-csharp-scriptingunity-physics