1
00:00:00,000 --> 00:00:01,000
Hello, guys.

2
00:00:01,000 --> 00:00:02,000
Welcome back.

3
00:00:02,000 --> 00:00:07,000
And in this video I want to make the player will not run until you press some button because now he

4
00:00:07,000 --> 00:00:08,000
starts immediately.

5
00:00:08,000 --> 00:00:10,000
And this is not how it should work.

6
00:00:10,000 --> 00:00:14,000
I guess So let's go to script again now.

7
00:00:14,000 --> 00:00:15,000
You know how to use input.

8
00:00:15,000 --> 00:00:17,000
Now you know why he's running?

9
00:00:17,000 --> 00:00:21,000
Because we change his velocity in the update function every frame.

10
00:00:21,000 --> 00:00:21,000
Right?

11
00:00:21,000 --> 00:00:23,000
So that's how that works.

12
00:00:23,000 --> 00:00:24,000
I want to use boolean this time.

13
00:00:24,000 --> 00:00:26,000
It's time for you to learn about boolean.

14
00:00:26,000 --> 00:00:34,000
I'll just create public boolean and I'll name it as run begun, run, begun.

15
00:00:34,000 --> 00:00:36,000
Now let's go to update and type.

16
00:00:36,000 --> 00:00:46,000
If run began equals equals to true, then let's put this line of code inside and we can just cut it

17
00:00:46,000 --> 00:00:48,000
out like that and paste it in.

18
00:00:48,000 --> 00:00:54,000
Or we can hold my old key or your like just old key.

19
00:00:54,000 --> 00:00:55,000
Nobody is old key.

20
00:00:55,000 --> 00:01:00,000
Just hold out and press arrow down or up to move them.

21
00:01:01,000 --> 00:01:02,000
I would like that.

22
00:01:02,000 --> 00:01:06,000
Then I click home button, click tap to make it cleaner to delete this one and it looks better.

23
00:01:06,000 --> 00:01:10,000
Now I'm going to tell you some more about clean code practice.

24
00:01:10,000 --> 00:01:11,000
Just stay with me on this one.

25
00:01:11,000 --> 00:01:13,000
We go back to Unity, let it assemble.

26
00:01:13,000 --> 00:01:14,000
We can see run.

27
00:01:14,000 --> 00:01:16,000
Begun is false.

28
00:01:16,000 --> 00:01:20,000
I don't really like the name, but we'll have to stick with it for now.

29
00:01:20,000 --> 00:01:22,000
And if I hit play, he's not running.

30
00:01:22,000 --> 00:01:26,000
But if I make it true, he's running.

31
00:01:27,000 --> 00:01:30,000
And he stops and running.

32
00:01:30,000 --> 00:01:35,000
Now I need the way to make him run from the keyboard.

33
00:01:35,000 --> 00:01:39,000
So I don't use this checkbox in the inspector.

34
00:01:39,000 --> 00:01:43,000
I use my keyboard and that is a challenge for you.

35
00:01:43,000 --> 00:01:45,000
And that is easy challenge.

36
00:01:45,000 --> 00:01:48,000
You probably know how to do this.

37
00:01:48,000 --> 00:01:53,000
So you pause the video and I'll count till two and then I'm going to show you how to do that.

38
00:01:54,000 --> 00:01:55,000
One, two.

39
00:01:55,000 --> 00:02:04,000
Okay, so we go to update maybe somewhere here and type if input get button down.

40
00:02:04,000 --> 00:02:06,000
And now we need a name of a button.

41
00:02:06,000 --> 00:02:09,000
Let's go and see this what we can use but can unity.

42
00:02:09,000 --> 00:02:12,000
We go to edit project settings.

43
00:02:12,000 --> 00:02:13,000
Hmm.

44
00:02:14,000 --> 00:02:15,000
Fire.

45
00:02:17,000 --> 00:02:21,000
So fire one is a mouse zero and fire two is a mouse one.

46
00:02:21,000 --> 00:02:25,000
So let's use fire to like the right button of the mouse.

47
00:02:25,000 --> 00:02:25,000
Yeah.

48
00:02:27,000 --> 00:02:30,000
Fire to then run begun.

49
00:02:31,000 --> 00:02:32,000
Equals to true.

50
00:02:33,000 --> 00:02:34,000
Let's go back.

51
00:02:36,000 --> 00:02:37,000
Now we start the game.

52
00:02:37,000 --> 00:02:38,000
Nothing happens.

53
00:02:38,000 --> 00:02:43,000
And if I click my right button on the mouse, he is running.

54
00:02:45,000 --> 00:02:46,000
And we can jump.

55
00:02:47,000 --> 00:02:48,000
Cool.

56
00:02:48,000 --> 00:02:49,000
That works.

57
00:02:49,000 --> 00:02:51,000
And I think you understand what we did there.

58
00:02:51,000 --> 00:02:55,000
Now, let's talk a bit about cleaning this because this looks bad.

59
00:02:55,000 --> 00:02:56,000
I don't like it.

60
00:02:56,000 --> 00:03:01,000
First, there is a different way to check if bullying is true or false.

61
00:03:01,000 --> 00:03:04,000
We use this one just for you to understand.

62
00:03:04,000 --> 00:03:08,000
If we want to check if it's false, we could do equals to false.

63
00:03:08,000 --> 00:03:10,000
Or we could do.

64
00:03:12,000 --> 00:03:12,000
Sorry.

65
00:03:14,000 --> 00:03:22,000
Not equal to true, but there is a different way we can just type if run begun and that just making

66
00:03:22,000 --> 00:03:24,000
check if run began is true.

67
00:03:24,000 --> 00:03:26,000
If we want to make sure it's false, we do.

68
00:03:26,000 --> 00:03:27,000
If.

69
00:03:27,000 --> 00:03:30,000
Not run begun with exclamation mark.

70
00:03:30,000 --> 00:03:32,000
But we're going to have more of that practice later.

71
00:03:32,000 --> 00:03:33,000
Don't worry about it.

72
00:03:34,000 --> 00:03:39,000
Now, something else here is you can see I'm writing my if statement and then I'm making curly brackets.

73
00:03:39,000 --> 00:03:45,000
But if in the curly brackets only one line of code, we don't have to type curly brackets at all.

74
00:03:45,000 --> 00:03:51,000
We can just make it look like this and this still will work the same.

75
00:03:51,000 --> 00:03:56,000
It works only if you have one line of code after the if statement, but I kind of like it to see this

76
00:03:56,000 --> 00:03:56,000
way.

77
00:03:56,000 --> 00:04:03,000
It looks much better and something else to do here because we already have a couple of inputs and later

78
00:04:03,000 --> 00:04:05,000
on we're going to put more code in the update.

79
00:04:05,000 --> 00:04:06,000
We need to make it look clean.

80
00:04:06,000 --> 00:04:07,000
We need to arrange it.

81
00:04:07,000 --> 00:04:17,000
So let's select all of these code like that click alt plus enter and we click extract method.

82
00:04:17,000 --> 00:04:22,000
Then let's give it a name and I'll name it as check input, click enter.

83
00:04:22,000 --> 00:04:29,000
And now we have function that holds all of the input info inside and we just call this function in the

84
00:04:29,000 --> 00:04:30,000
update.

85
00:04:30,000 --> 00:04:31,000
So basically it works the same.

86
00:04:31,000 --> 00:04:38,000
If for some reason your alternator didn't work, then you can just create a function like private void

87
00:04:39,000 --> 00:04:45,000
check and check input and just copy this code inside.

88
00:04:46,000 --> 00:04:46,000
Think a bet?

89
00:04:47,000 --> 00:04:47,000
Yeah.

90
00:04:47,000 --> 00:04:48,000
All right.

91
00:04:49,000 --> 00:04:50,000
Good.

92
00:04:50,000 --> 00:04:50,000
We began.

93
00:04:50,000 --> 00:04:51,000
Very good.

94
00:04:51,000 --> 00:04:53,000
Let's go further.

95
00:04:53,000 --> 00:04:54,000
Let's go to next video.

