>> Hello, welcome to our Unity 101 series.
I'm Abdulla. In our last video,
we really got comfortable coding for Unity in C#.
In this new video,
I'm going to teach you how to use the input system,
probably the most important system in
video games ever. Player input.
Let's get started. Let's install Unity's Input System.
To do that, we go to "Window",
"Package Manager", and then search for "Input System".
Click on that, and then we click "Install".
A warning pop-up might appear asking you if you want to
switch from the native input system to the new input system,
you should choose "Yes".
At this moment, Unity will restart your project.
Let's check if the input system was installed
correctly and go to "Package Manager" again
and see that the input system is up-to-date down here.
Now let's start with the input system
by going to "Edit Project Settings",
and then we'll see that there's an entry on
the left for input system.
Press on "Creates Settings Asset".
This will create a file that will
manage the input system settings.
Now if you click on "Player" on the left side
there and scroll all the way down,
we can see that we're using
the input system package instead of the old input manager.
More on Player settings in a future video.
Now we're ready to use the input system.
Double-click on "Rotating Cube Script," open up "Visual Studio".
At the top, let's type using unityengine.inputsystem.
This will include the Input System library in our script.
To use the input library,
let's first create a public variable for our keyboard.
Let's type Public Type keyboard with the name of keyboard.
Now let's assign the current active keyboard
to our keyboard variable.
By typing keyboard equals to keyboard.current.
The thing that I want to do now is rotate the cube if
the W button was pressed on the keyboard and to do that,
I want to capture the changes to the keyboard in the update loop,
then rotate the cube there.
To do that, we create an if statement to
make sure that the keyboard is not null.
Then we create another if statement
with keyboard.wkey.ispressed inside of it.
This will return true if the W key is pressed,
and it will return false if the W key is not pressed.
If it's true, rotate the cube
and then print "Update to a Console".
If you remember the update function will update every frame.
But our human brains don't operate in
frames per second as a unit of time.
So if we will multiply the rotation by
the amount of time that has elapsed since
the last frame and that's provided
by the Unity engine under time.deltatime.
This will make it so the amount of rotation will
be per unit of time and not per frame.
This makes it a lot easier when you're
designing the game later on in the Unity editor.
Now if we go back to the "Unity Editor",
press "Play" and then press "W" on our keyboard,
we will see update being printed to our console.
As you can see, the rotation is very
slow because right now we have set the Y rotation to two,
and that's happening every second.
We want to increase it to something like
50 rotation units per second.
Now the cube is rotating by 50
every second and not for every frame.
If the game slowed down for any reason,
the cube will still continue rotating
regardless of how many frames
the engine rendered on the screen.
Wasn't that exciting?
This is by far my favorite subject within game development.
I mean, game feel.
But what we did today just scratched
the surface of Unity's Input System.
I highly recommend that you go to Unity's documentation
and read more about their new input system.
Join us next time when I talk about another very exciting topic,
physics and collisions. I'll see you there.
[MUSIC]