0
0
Unityframework~30 mins

Input action maps in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Input Action Maps in Unity
📖 Scenario: You are creating a simple Unity game where the player can move a character using keyboard inputs. To manage these inputs cleanly, you will use Input Action Maps, which help organize input controls.
🎯 Goal: Build a Unity script that sets up an Input Action Map for player movement and reads input values to move the character.
📋 What You'll Learn
Create an Input Action Map called playerActions with an action move
Add a Vector2 binding to move for keyboard WASD keys
Create a variable moveInput to store the current movement input
Print the moveInput value each frame to see the input
💡 Why This Matters
🌍 Real World
Input Action Maps help organize player controls in games, making it easier to manage different input devices and actions.
💼 Career
Game developers use Input System features like action maps to create flexible and maintainable input handling in professional Unity projects.
Progress0 / 4 steps
1
Create the Input Action Map and move action
Create an InputActionMap called playerActions and add an InputAction called move with type Value and control type Vector2.
Unity
Need a hint?

Use new InputActionMap("Player") to create the map and AddAction to add the move action.

2
Add WASD keyboard bindings to the move action
Add a composite binding of type 2DVector to the move action with these parts: up bound to W, down to S, left to A, and right to D keys on the keyboard.
Unity
Need a hint?

Use AddCompositeBinding("2DVector") and chain With calls for each direction.

3
Enable the action map and read input
Enable the playerActions map and create a Vector2 variable called moveInput. Use move.ReadValue<Vector2>() to update moveInput each frame inside an Update method.
Unity
Need a hint?

Call playerActions.Enable() in Start() and update moveInput in Update().

4
Print the move input value each frame
Add a Debug.Log statement inside the Update method to print the current moveInput value.
Unity
Need a hint?

Use Debug.Log(moveInput); inside Update() to see the input values in the console.