Input System
Learn how Unity’s input system can help create responsive and interactive experiences.
Introduction
In game development, user input is a fundamental aspect that allows players to interact with and control the game. Unity provides two input systems: the old Input System
package and the new Input System
package. In this lesson, we'll explore both input systems, their features, and how to use them in our Unity projects.
The old Input System
package
The old Input System is the legacy input system in Unity. It has been widely used in previous versions and is still compatible with the latest Unity releases. This input system relies on the Input
class and provides various methods to handle user input, such as GetKey
, GetButton
, and GetAxis
. These methods allow us to detect keyboard, mouse, and controller inputs. The old Input System is straightforward and suitable for simple input requirements.
Using the old Input System in Unity
In this example, we’ll demonstrate how to use Unity’s old Input System to detect keyboard input for player movement in a 3D environment. We’ll create a scene where a player object moves horizontally using the arrow keys.
The step-by-step instructions
Scene setup:
Begin by creating a new scene in Unity.
Set up a scene with a simple 3D character representing the player. This can be a cube.
Ensure that the player object is on a flat surface for movement. We can use a plane from the same menu we created a cube.
Create a script:
Create a new C# script in our project named
PlayerMovement
.Open the script in the preferred code editor.
Get hands-on with 1400+ tech skills courses.