📖 Scenario: You are creating a simple Unity project to understand how the New Input System works. This system helps your game detect player actions like moving or jumping in a clean and flexible way.
🎯 Goal: Build a basic Unity script that sets up the New Input System to read player movement input and print the movement direction.
📋 What You'll Learn
Create an InputAction asset with a 'Move' action
Set up a Vector2 variable to store movement input
Write a method to read the 'Move' input value
Print the movement input direction when it changes
💡 Why This Matters
🌍 Real World
Game developers use the New Input System in Unity to handle player controls cleanly and support multiple devices like keyboard, gamepad, and touch.
💼 Career
Understanding the New Input System is essential for Unity game developers to create responsive and flexible player input handling.
Progress0 / 4 steps
1
Create InputAction asset with 'Move' action
Create an InputAction asset called playerInputActions with a Move action of type Value and control type Vector2.
Unity
Hint
Use Unity's InputAction class to define a 'Move' action with type Value and Vector2 control.
2
Add Vector2 variable to store movement input
Add a Vector2 variable called movementInput to store the player's movement direction.
Unity
Hint
Declare a public Vector2 variable named movementInput inside the PlayerController class.
3
Read 'Move' input value in Update method
In the PlayerController class, write an Update() method that reads the Move action's current value into movementInput using ReadValue<Vector2>().
Unity
Hint
Inside Update(), assign movementInput by calling playerInputActions.Move.ReadValue<Vector2>()
4
Print movement direction when input changes
Add a Debug.Log statement inside Update() to print the current movementInput value whenever it changes.
Unity
Hint
Use Debug.Log to print the movementInput value inside Update().
Practice
(1/5)
1. What is the main purpose of the New Input System in Unity?
easy
A. To create 3D models for games
B. To handle multiple input devices easily and flexibly
C. To manage game physics and collisions
D. To optimize game graphics performance
Solution
Step 1: Understand the role of input systems
The New Input System is designed to manage inputs from devices like keyboard, mouse, gamepads, etc.
Step 2: Compare with other options
Options B, C, and D relate to graphics, physics, or modeling, not input handling.
Final Answer:
To handle multiple input devices easily and flexibly -> Option B
Quick Check:
New Input System = device input management [OK]
Hint: Focus on input device management purpose [OK]
Common Mistakes:
Confusing input system with graphics or physics
Thinking it only handles keyboard input
Assuming it creates game assets
2. Which of the following is the correct way to enable an input action in the New Input System?
easy
A. inputAction.Run();
B. inputAction.Start();
C. inputAction.Activate();
D. inputAction.Enable();
Solution
Step 1: Recall method names in New Input System
The method to activate an input action is called Enable(), not Start(), Activate(), or Run().
Step 2: Confirm syntax correctness
inputAction.Enable(); is the correct syntax to enable the action.