1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:02,000
In this section, we're going to work on animations.

3
00:00:02,000 --> 00:00:06,000
We're going to make simple animation like it'll run, jump and fall.

4
00:00:06,000 --> 00:00:09,000
And to make that first, we need an animator.

5
00:00:09,000 --> 00:00:14,000
I think it's best to practice on animations by making them, and we're going to do that.

6
00:00:14,000 --> 00:00:19,000
And later, I'm going to tell you some more info about animations like how it works, how the transition

7
00:00:19,000 --> 00:00:20,000
work and so on.

8
00:00:20,000 --> 00:00:23,000
First, just repeat after me so it will be easier to understand later.

9
00:00:24,000 --> 00:00:27,000
Let's select the player and then click add component.

10
00:00:27,000 --> 00:00:29,000
And here I already have it.

11
00:00:29,000 --> 00:00:33,000
We need to type animator and select it.

12
00:00:33,000 --> 00:00:40,000
Now we can see that animator has controller field and we need to fill that with animator controller.

13
00:00:40,000 --> 00:00:49,000
So let's click right button, create animator controller and we name it as player player, a C as an

14
00:00:49,000 --> 00:00:50,000
animator controller.

15
00:00:50,000 --> 00:00:53,000
Now let's select the player and drag it here.

16
00:00:53,000 --> 00:00:59,000
There is also an avatar, but we don't need that avatar needed when you work with the 3D models and

17
00:00:59,000 --> 00:01:03,000
rig skeleton and so on, so we don't have to worry about it.

18
00:01:03,000 --> 00:01:08,000
Let's go to Window Animation Animator.

19
00:01:09,000 --> 00:01:13,000
And now we can see what is inside of this animator.

20
00:01:13,000 --> 00:01:20,000
So basically this window now shows us what is inside of this animator.

21
00:01:20,000 --> 00:01:22,000
Now it's time to make some animations.

22
00:01:22,000 --> 00:01:26,000
And for that, we're going to go to window animation.

23
00:01:26,000 --> 00:01:27,000
Animation.

24
00:01:28,000 --> 00:01:30,000
I want to take this window and drag it over here.

25
00:01:31,000 --> 00:01:32,000
That's cool.

26
00:01:33,000 --> 00:01:38,000
Now we can click create and I think it's best to keep it arranged.

27
00:01:38,000 --> 00:01:42,000
So let's make a new folder that we're going to call animation.

28
00:01:42,000 --> 00:01:44,000
So animation, see us.

29
00:01:44,000 --> 00:01:49,000
Let's open it and inside I'll name it as player Idol.

30
00:01:49,000 --> 00:01:50,000
Cool.

31
00:01:50,000 --> 00:01:53,000
Now let's go to graphics player.

32
00:01:53,000 --> 00:01:54,000
Idol folder.

33
00:01:54,000 --> 00:01:57,000
Take all of the sprites and drag them over here.

34
00:01:57,000 --> 00:02:01,000
We can click play to see how animation looks at the moment.

35
00:02:01,000 --> 00:02:03,000
And I think it's kind of fast.

36
00:02:03,000 --> 00:02:04,000
So we can make it slower.

37
00:02:04,000 --> 00:02:07,000
We can do that by changing sample rate over here.

38
00:02:07,000 --> 00:02:14,000
And in case you don't see sample rate, we need to go to this three dots, click it and choose show

39
00:02:14,000 --> 00:02:15,000
sample rate.

40
00:02:17,000 --> 00:02:18,000
To make it appear.

41
00:02:18,000 --> 00:02:22,000
Now, let's try to set 15 over here and see how it looks.

42
00:02:23,000 --> 00:02:24,000
Okay, that looks much better.

43
00:02:25,000 --> 00:02:30,000
Now, if we go to any meter, we can see we got player idle animation over here.

44
00:02:30,000 --> 00:02:33,000
Orange color means animation was set as a default.

45
00:02:33,000 --> 00:02:37,000
Now if we go to play mode, we can see our character is moving.

46
00:02:37,000 --> 00:02:42,000
He is in idle animation and basically that's it for this video.

47
00:02:42,000 --> 00:02:43,000
We are done.

48
00:02:43,000 --> 00:02:49,000
We made the animator controller and now our character is breathing and he looks more alive.

49
00:02:49,000 --> 00:02:53,000
Before we finish, though, I want to do some changes in the script.

50
00:02:53,000 --> 00:02:55,000
Let's go over here.

51
00:02:55,000 --> 00:03:00,000
And first of all, I want to say we need to make a component animator because we're going to use it

52
00:03:00,000 --> 00:03:01,000
later.

53
00:03:01,000 --> 00:03:05,000
We have components on the game object, but we don't have access to components from this script.

54
00:03:05,000 --> 00:03:07,000
So let's type here.

55
00:03:08,000 --> 00:03:10,000
Public animator.

56
00:03:11,000 --> 00:03:12,000
Anyone.

57
00:03:13,000 --> 00:03:15,000
All right, let's save it.

58
00:03:15,000 --> 00:03:16,000
Go back and drag it here.

59
00:03:16,000 --> 00:03:23,000
Now we have access to the animator controller, but I actually want to keep this script a bit cleaner

60
00:03:23,000 --> 00:03:28,000
and show as less info as possible, because later on, we're going to have a lot of stuff in there,

61
00:03:28,000 --> 00:03:32,000
and it's going to be so huge it might not even fit into the inspector.

62
00:03:32,000 --> 00:03:39,000
So there is a way to hide this rigid body animator and assign them at the same time from the script.

63
00:03:39,000 --> 00:03:45,000
All right, let's go back to script and now I'll just make this window smaller so we can see.

64
00:03:45,000 --> 00:03:48,000
Inspector, I will change this public to private.

65
00:03:49,000 --> 00:03:51,000
Same as here, and I'm going to save it.

66
00:03:51,000 --> 00:03:53,000
Now we go back to Unity.

67
00:03:56,000 --> 00:03:58,000
We can see it's disappeared.

68
00:03:58,000 --> 00:04:00,000
But still we need to assign it.

69
00:04:00,000 --> 00:04:01,000
So how we can do that?

70
00:04:01,000 --> 00:04:10,000
We can go to start function over here and type RB equals to get component, which is basically means

71
00:04:10,000 --> 00:04:11,000
what it means.

72
00:04:11,000 --> 00:04:17,000
RB will be equals to the value and that value is equals to get component of rigid body to dx.

73
00:04:20,000 --> 00:04:27,000
And you're going to do the same for the animator animate equals to get component of animator.

74
00:04:27,000 --> 00:04:31,000
Now it is not visible, but we have access to the component.

75
00:04:31,000 --> 00:04:37,000
And if I try to play my game right now, I still can access rigid body, let's say from a jump.

76
00:04:37,000 --> 00:04:39,000
Now I want to do something else in here.

77
00:04:39,000 --> 00:04:43,000
It is best practice to keep variables private if you can.

78
00:04:43,000 --> 00:04:48,000
If you don't have a reason to make it public, then don't do it.

79
00:04:48,000 --> 00:04:52,000
And before we had the reason, because I wanted to see it in the inspector, but I didn't want to confuse

80
00:04:52,000 --> 00:04:55,000
you with a lot of extra info that you don't need at the beginning.

81
00:04:55,000 --> 00:04:57,000
But now I think you're ready.

82
00:04:57,000 --> 00:05:01,000
So let's go over here and type private instead of public.

83
00:05:01,000 --> 00:05:04,000
And now if we say it, you know it's not going to be visible.

84
00:05:04,000 --> 00:05:09,000
So basically now we cannot change ground check distance because it's not here.

85
00:05:09,000 --> 00:05:10,000
But we can fix that.

86
00:05:10,000 --> 00:05:14,000
We can go and type serialize field just in front of it.

87
00:05:14,000 --> 00:05:17,000
And while we are here, let's do same for Layer Mask.

88
00:05:20,000 --> 00:05:20,000
Private.

89
00:05:21,000 --> 00:05:25,000
And let's do the same for jumpers and move speed.

90
00:05:25,000 --> 00:05:33,000
Let's make it serialized field private float and here as well, serialized field, private jump force.

91
00:05:33,000 --> 00:05:38,000
Now, if I go back to Unity, I can see variables still there.

92
00:05:38,000 --> 00:05:45,000
I can control them, but they are private and they are accessible only from the script and from this

93
00:05:45,000 --> 00:05:49,000
script only if I try to get them from another script.

94
00:05:49,000 --> 00:05:51,000
It is not possible because they are private.

95
00:05:51,000 --> 00:05:58,000
Something else to mention here When you create in a private variable, you don't have to type private.

96
00:05:58,000 --> 00:05:59,000
Exactly.

97
00:05:59,000 --> 00:06:06,000
It could be just, let's say serialize, field float and power.

98
00:06:06,000 --> 00:06:07,000
I'll just type power.

99
00:06:07,000 --> 00:06:08,000
This is an example.

100
00:06:09,000 --> 00:06:11,000
Now, if I go back to Unity, it happens.

101
00:06:11,000 --> 00:06:16,000
Because if you don't mention is it private or public, it's going to be private by default.

102
00:06:16,000 --> 00:06:21,000
And let's say when you prototype in, it is really handy to just quickly type float power instead of

103
00:06:21,000 --> 00:06:23,000
private and wasting your time for that.

104
00:06:23,000 --> 00:06:28,000
But I prefer to type it so it's easier to understand, especially for beginners.

105
00:06:28,000 --> 00:06:28,000
All right.

106
00:06:28,000 --> 00:06:29,000
What is private and what is public?

107
00:06:30,000 --> 00:06:31,000
That's enough for this video.

108
00:06:31,000 --> 00:06:32,000
And let's go to next one.

