CROSS-PLATFORM INPUT • C#
UNITY INPUT SYSTEM BEGINNER GUIDE
Migrate away from legacy Input.GetKey to Unity's modern, event-driven Input System with seamless support for Keyboard, Gamepad controllers, and Mobile Touchscreens.
Quick Answer
Install the com.unity.inputsystem package via Package Manager. Enable Active Input Handling: Both in Project Settings. Create an InputActionAsset, or read input directly in C# using Gamepad.current or Keyboard.current without polling strings.
1
Direct C# Input System Reading Example
ModernPlayerInput.cs (C#)
using UnityEngine;
using UnityEngine.InputSystem;
public class ModernPlayerInput : MonoBehaviour
{
[Header("Input Values")]
public Vector2 MoveVector { get; private set; }
public bool IsFirePressed { get; private set; }
public bool IsJumpPressed { get; private set; }
private void Update()
{
Vector2 input = Vector2.zero;
// 1. Read Keyboard
if (Keyboard.current != null)
{
if (Keyboard.current.wKey.isPressed || Keyboard.current.upArrowKey.isPressed) input.y += 1f;
if (Keyboard.current.sKey.isPressed || Keyboard.current.downArrowKey.isPressed) input.y -= 1f;
if (Keyboard.current.aKey.isPressed || Keyboard.current.leftArrowKey.isPressed) input.x -= 1f;
if (Keyboard.current.dKey.isPressed || Keyboard.current.rightArrowKey.isPressed) input.x += 1f;
IsFirePressed = Keyboard.current.spaceKey.isPressed;
}
// 2. Read Gamepad (Xbox / PlayStation / Mobile Controller)
if (Gamepad.current != null)
{
Vector2 stick = Gamepad.current.leftStick.ReadValue();
if (stick.sqrMagnitude > 0.05f)
{
input = stick; // Analog stick precision
}
if (Gamepad.current.rightTrigger.isPressed || Gamepad.current.buttonSouth.isPressed)
{
IsFirePressed = true;
}
}
MoveVector = input;
}
}
Encountering Input System Compiler or Runtime Errors?
Check out our error solutions: InvalidOperationException Fix • Input Manager Deprecation Fix