Summary

Unity’s legacy Input Manager provides a straightforward API for reading keyboard and mouse input inside Update. The two most common methods for movement are Input.GetAxisRaw and Input.GetAxis, which read named axes configured in Project Settings. For specific keys, Input.GetKey, Input.GetKeyDown, and Input.GetKeyUp take a KeyCode enum value.


Key ideas

Input.GetAxisRaw(string axisName) returns -1, 0, or 1 with no interpolation. The “Horizontal” axis maps to A/D and left/right arrow keys. “Vertical” maps to W/S and up/down arrow keys. Recommended for beginners because the result is always a clean integer-like value.

Input.GetAxis(string axisName) returns a float between -1 and 1 with built-in acceleration and deceleration smoothing. Produces more natural-feeling analogue movement but makes the value harder to reason about precisely.

Input.GetKey(KeyCode key) returns true every frame the key is held down. Use for held modifiers (sprint, aim) and for continuous actions.

Input.GetKeyDown(KeyCode key) returns true only on the single frame the key is first pressed. Use for one-shot actions: jump, attack, interact.

Input.GetKeyUp(KeyCode key) returns true only on the frame the key is released.


In practice

Reading movement axes:

void Update()
{
    // Returns -1, 0, or 1. No smoothing.
    float horizontal = Input.GetAxisRaw("Horizontal");  // A/D or left/right arrows
    float vertical   = Input.GetAxisRaw("Vertical");    // W/S or up/down arrows
 
    transform.Translate(horizontal * moveSpeed * Time.deltaTime,
                        vertical   * moveSpeed * Time.deltaTime, 0f);
}

Sprint modifier (held key):

float currentSpeed = Input.GetKey(KeyCode.LeftShift)
    ? moveSpeed * sprintMultiplier
    : moveSpeed;

One-shot action (key press):

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        Jump();  // fires once per press, not every frame
    }
}

Common KeyCode values:

KeyCodeKey
KeyCode.SpaceSpace bar
KeyCode.LeftShiftLeft Shift
KeyCode.EE key
KeyCode.EscapeEscape
KeyCode.ReturnEnter

Gotchas

  • Input.GetAxisRaw vs Input.GetAxis: for top-down or grid-like 2D movement, GetAxisRaw is almost always clearer. GetAxis is better for analogue controller feel or vehicle steering.
  • All Input calls must happen inside Update (or a method called from Update). Calling them in Start or FixedUpdate will miss inputs or behave unexpectedly.
  • Axis names (“Horizontal”, “Vertical”) are case-sensitive and must match entries in Edit > Project Settings > Input Manager exactly.
  • The Input Manager is Unity’s legacy input system. Unity 6 also includes the newer Input System package (separate API). CRE132 uses the legacy system.

Practice

Create a player script that does three things:

  • moves with Input.GetAxisRaw("Horizontal") and Input.GetAxisRaw("Vertical")
  • sprints while Left Shift is held
  • logs "Jump" once when Space is pressed

Success test:

  • holding Space does not spam jump logs
  • holding Left Shift changes movement speed every frame
  • releasing movement keys returns axis values to 0

Extension:

  • swap GetAxisRaw for GetAxis and describe the difference in movement feel

Self-test

  1. Which method returns only -1, 0 or 1: GetAxis or GetAxisRaw?
  2. Which method is correct for a one-shot jump: GetKey or GetKeyDown?
  3. Why should input normally be read in Update?
  4. What happens if the axis name is misspelled?
  5. Why is GetAxisRaw often easier for beginners?

Answers

  1. Input.GetAxisRaw.
  2. Input.GetKeyDown, because it fires once on the first pressed frame.
  3. Update runs every rendered frame, so it is less likely to miss short input presses.
  4. Unity cannot find the configured axis, so the input will not behave as expected.
  5. The value is clean and predictable: left or down is -1, no input is 0, right or up is 1.