The Input System
Player input, keyboard, mouse, gamepad, touch, needs to be read every frame and turned into game actions.
using UnityEngine;
public class LegacyMovement : MonoBehaviour
{
public float speed = 5f;
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
Jump();
}
}
The old way: the Input class
Input.GetAxis("Horizontal")returns a smoothed value between -1 and 1, built from whatever keys/sticks are bound to that axis in Project Settings.Input.GetKeyDown(KeyCode.Space)is true for exactly one frame, the frame the key was pressed, useGetKeyfor "is it currently held."Input.GetButtonDown("Fire1")reads a named action the same way, but through the configurable Input Manager instead of a hardcoded key.
The new Input System package
Unity's newer Input System package models input as Actions ("Move", "Jump", "Fire") bound to any device, instead of hardcoded keys, so the same script works with keyboard, gamepad, or touch without changes.
using UnityEngine.InputSystem;
public class NewMovement : MonoBehaviour
{
public InputAction moveAction;
void OnEnable() => moveAction.Enable();
void Update()
{
Vector2 move = moveAction.ReadValue<Vector2>();
transform.Translate(new Vector3(move.x, 0, move.y) * Time.deltaTime);
}
}
Both systems are valid, the legacy Input class is simpler for small projects, the Input System package scales better for multi-device support and rebindable controls.