Hello, guys.
Welcome back.
And in this video I want to make the player will not run until you press some button because now he
starts immediately.
And this is not how it should work.
I guess So let's go to script again now.
You know how to use input.
Now you know why he's running?
Because we change his velocity in the update function every frame.
Right?
So that's how that works.
I want to use boolean this time.
It's time for you to learn about boolean.
I'll just create public boolean and I'll name it as run begun, run, begun.
Now let's go to update and type.
If run began equals equals to true, then let's put this line of code inside and we can just cut it
out like that and paste it in.
Or we can hold my old key or your like just old key.
Nobody is old key.
Just hold out and press arrow down or up to move them.
I would like that.
Then I click home button, click tap to make it cleaner to delete this one and it looks better.
Now I'm going to tell you some more about clean code practice.
Just stay with me on this one.
We go back to Unity, let it assemble.
We can see run.
Begun is false.
I don't really like the name, but we'll have to stick with it for now.
And if I hit play, he's not running.
But if I make it true, he's running.
And he stops and running.
Now I need the way to make him run from the keyboard.
So I don't use this checkbox in the inspector.
I use my keyboard and that is a challenge for you.
And that is easy challenge.
You probably know how to do this.
So you pause the video and I'll count till two and then I'm going to show you how to do that.
One, two.
Okay, so we go to update maybe somewhere here and type if input get button down.
And now we need a name of a button.
Let's go and see this what we can use but can unity.
We go to edit project settings.
Hmm.
Fire.
So fire one is a mouse zero and fire two is a mouse one.
So let's use fire to like the right button of the mouse.
Yeah.
Fire to then run begun.
Equals to true.
Let's go back.
Now we start the game.
Nothing happens.
And if I click my right button on the mouse, he is running.
And we can jump.
Cool.
That works.
And I think you understand what we did there.
Now, let's talk a bit about cleaning this because this looks bad.
I don't like it.
First, there is a different way to check if bullying is true or false.
We use this one just for you to understand.
If we want to check if it's false, we could do equals to false.
Or we could do.
Sorry.
Not equal to true, but there is a different way we can just type if run begun and that just making
check if run began is true.
If we want to make sure it's false, we do.
If.
Not run begun with exclamation mark.
But we're going to have more of that practice later.
Don't worry about it.
Now, something else here is you can see I'm writing my if statement and then I'm making curly brackets.
But if in the curly brackets only one line of code, we don't have to type curly brackets at all.
We can just make it look like this and this still will work the same.
It works only if you have one line of code after the if statement, but I kind of like it to see this
way.
It looks much better and something else to do here because we already have a couple of inputs and later
on we're going to put more code in the update.
We need to make it look clean.
We need to arrange it.
So let's select all of these code like that click alt plus enter and we click extract method.
Then let's give it a name and I'll name it as check input, click enter.
And now we have function that holds all of the input info inside and we just call this function in the
update.
So basically it works the same.
If for some reason your alternator didn't work, then you can just create a function like private void
check and check input and just copy this code inside.
Think a bet?
Yeah.
All right.
Good.
We began.
Very good.
Let's go further.
Let's go to next video.