WEBVTT

00:00.000 --> 00:00.420
Hello guys.

00:00.420 --> 00:01.380
Welcome to the video.

00:01.380 --> 00:07.650
In this one I want to tell you about very important aspect of development and that is components of

00:07.650 --> 00:08.340
unity.

00:08.340 --> 00:13.590
So for now I'm going to delete this full image over here.

00:13.590 --> 00:14.610
Let's delete it.

00:14.610 --> 00:19.830
And let's just click right button and click Create Empty.

00:20.040 --> 00:24.300
So now we can see we have a game object that is empty.

00:24.300 --> 00:27.150
And it has only one component transform.

00:27.150 --> 00:28.830
Transform cannot be removed.

00:28.830 --> 00:30.300
It is there by default.

00:30.720 --> 00:36.570
And transform is needed to define where object is in the world, what is rotation and what's his scale.

00:36.570 --> 00:37.890
That is very important.

00:37.890 --> 00:44.370
So transform is a component, and there are other components that we need to give certain properties

00:44.370 --> 00:48.720
to the game object or set certain behavior on the game object.

00:48.720 --> 00:53.130
We can imagine like you know, game object is like a car, for example.

00:53.130 --> 01:01.500
And just as a car has different parts like engine wheels, lights, and each part gives different functionality

01:01.500 --> 01:05.700
to the car, same way components give different functionality to the game object.

01:05.700 --> 01:08.940
As example, we have an empty game object and it does nothing.

01:08.940 --> 01:09.900
It is just there.

01:09.900 --> 01:13.950
But let's say we create 2D sprite square.

01:14.830 --> 01:21.970
We can see that this square has a transform, same as the previous one, but also it has a sprite renderer

01:21.970 --> 01:25.420
and this one responsible for the visuals of this game object.

01:25.450 --> 01:32.680
Now that we know that this square looks like this because it has sprite renderer, uh, let's change

01:32.680 --> 01:34.630
color of this square.

01:36.250 --> 01:39.880
To something darker and let's just rename it.

01:40.810 --> 01:42.910
To platform.

01:43.740 --> 01:44.430
Okay.

01:44.430 --> 01:46.740
Now I'm going to select this platform.

01:46.860 --> 01:47.730
Press move tool.

01:47.730 --> 01:48.630
Move it down.

01:48.630 --> 01:52.260
And then I want to stretch it just like so.

01:52.650 --> 01:55.740
So now we created a game object platform I'm sorry for the name.

01:59.010 --> 01:59.400
Yeah.

01:59.400 --> 02:06.420
So now we created a game object that is platform, and it has the dark blue color and it has this shape

02:06.420 --> 02:08.940
because we changed the scale on the transform.

02:08.940 --> 02:11.010
Now we can create another object.

02:11.010 --> 02:18.540
Let's do 2D sprite circle and let's name it as player maybe okay.

02:18.540 --> 02:23.820
So now we have another game object in the game that has very similar components.

02:23.820 --> 02:26.730
And we want player to behave in a certain way.

02:26.730 --> 02:32.850
For example, we want this player which looks like a ball to fall when we play the game.

02:32.850 --> 02:35.340
We want it to be affected by gravity.

02:35.370 --> 02:36.480
How could we do that?

02:36.480 --> 02:41.670
Well, we could achieve that by adding new component to this game object.

02:41.730 --> 02:44.730
Let's go over here and click Add Component.

02:45.610 --> 02:51.010
And here you can see we have so many components, so many different things, but we're going to discuss

02:51.010 --> 02:51.940
them as we use them.

02:51.940 --> 02:53.380
So don't worry about everything.

02:53.380 --> 02:56.470
Just type rigidbody in the search field.

02:56.470 --> 03:00.520
And here we need to choose 2D because we work with the 2D objects.

03:00.520 --> 03:01.750
Let's click 2D.

03:01.780 --> 03:08.860
Now this object not only has visuals of a circle of a white color, but also it has a rigid body and

03:08.860 --> 03:14.170
that makes it behave like an object, like a physical object in a game world.

03:14.170 --> 03:20.500
If we select here, play focus so it will not open full screen and go to play mode.

03:22.270 --> 03:24.430
You can see that player now is falling down.

03:24.430 --> 03:28.270
So we change the behavior of the object by adding a component.

03:28.450 --> 03:31.630
And game development is just about that.

03:31.630 --> 03:36.490
You take an object, you give it different components and define how you want it to behave.

03:36.490 --> 03:41.530
And you set this behavior with a component that you put on the game object.

03:41.530 --> 03:44.800
Also, there is a way to create custom components.

03:44.800 --> 03:46.120
We call them scripts.

03:46.120 --> 03:48.820
They are just behavior as we need.

03:48.820 --> 03:51.640
But as of now let's just try to do something else.

03:52.280 --> 03:57.590
Let's say we have this ball falling and we like it, and we like how it looks, but we don't like that

03:57.590 --> 03:59.840
it is falling through the platform.

03:59.840 --> 04:04.760
That happens because unity does not know what is the shape of the object.

04:04.760 --> 04:10.160
It knows how it looks, it knows it's supposed to fall, and it's supposed to be affected by gravity,

04:10.160 --> 04:14.120
but it doesn't know what is the shape, where is the end of the object?

04:14.120 --> 04:15.890
Maybe just like that.

04:16.190 --> 04:17.420
Maybe it's just like that.

04:17.420 --> 04:18.530
Unity doesn't know.

04:18.530 --> 04:25.550
So we have to add another component to tell unity, hey, this object has this shape, and shape is

04:25.550 --> 04:29.510
usually defined by the colliders that we put on the object.

04:29.840 --> 04:32.030
So let's click Add Component.

04:32.030 --> 04:37.910
And because this is a circle over here we can just type circle Collider 2D.

04:37.910 --> 04:39.380
And let's just choose it.

04:40.140 --> 04:40.620
Now.

04:40.620 --> 04:46.470
By default it will take the shape of the sprite, but if we would want to make it bigger, we could

04:46.470 --> 04:51.690
choose Edit Collider and Stretch Collider to the size we want.

04:51.720 --> 04:54.570
However, we don't want to stretch Collider right now.

04:54.570 --> 04:59.520
It is okay, so let's just click reset and it's going to be default as it was before.

04:59.520 --> 05:05.640
And now let's go to the play mode and see if ball will be stopped by the platform.

05:09.140 --> 05:11.240
And no, it fell through the platform.

05:11.240 --> 05:12.080
Same as before.

05:12.080 --> 05:12.920
Why is that?

05:12.920 --> 05:14.540
Well, that is very simple.

05:14.540 --> 05:17.150
You need to knows what is the shape of this object.

05:17.150 --> 05:20.180
You need to know what is the collision should be for this object.

05:20.180 --> 05:23.960
But you need to know nothing about collision on this platform.

05:23.960 --> 05:26.570
So we have to add component here.

05:26.570 --> 05:29.510
And for example type box collider 2D.

05:31.870 --> 05:33.880
Now again it will take shape of a sprite.

05:33.880 --> 05:35.980
So we don't need to edit anything here.

05:35.980 --> 05:39.430
And let's just go to play mode right now and try it out.

05:40.320 --> 05:43.800
And boom ball is falling on the platform.

05:43.800 --> 05:44.610
Very cool.

05:44.610 --> 05:47.910
So believe me or not, this is already a game.

05:47.910 --> 05:50.250
In fact, we could do something here.

05:50.250 --> 05:59.340
Let's, um, let's click right button create and we need to find 2D physics material 2D okay.

05:59.340 --> 06:01.710
Let's just call it matte for now.

06:01.710 --> 06:06.120
I'm going to exit play mode because when you do changes in the play mode they are not saved.

06:07.820 --> 06:11.060
And here on the material, let's add Bounciness here.

06:11.060 --> 06:13.280
Let's just make it maybe as one.

06:13.280 --> 06:18.140
And then let's take the player and drag this material on the collider.

06:18.440 --> 06:20.120
And let's go back to the play mode.

06:21.790 --> 06:24.400
And now we can see ball is jumping.

06:24.430 --> 06:25.090
Very cool.

06:25.090 --> 06:25.720
Right.

06:25.990 --> 06:28.450
We can take the platform and play tennis.

06:29.930 --> 06:30.590
You.

06:31.760 --> 06:32.150
You.

06:34.120 --> 06:34.480
Yeah.

06:34.480 --> 06:42.040
So this is how you use components and components properties to change behavior of game objects.

06:42.040 --> 06:43.360
I'm going to delete this material.

06:43.360 --> 06:44.230
We don't need it anymore.

06:44.230 --> 06:45.640
It was just an example.

06:45.640 --> 06:47.500
And remove it from here.

06:48.280 --> 06:53.590
Now these are components that are predefined by unity and we're going to use them a lot.

06:53.620 --> 06:57.910
You can also make custom components and that is very easy to achieve.

06:57.940 --> 07:04.060
We can create C sharp script let's call it player for example.

07:04.060 --> 07:10.480
And with the help of this custom script we can adjust behavior of the object just as we want.

07:10.510 --> 07:15.700
We're going to talk more about basics of programming later on in the course, but for now, let's just

07:15.700 --> 07:16.300
try this.

07:16.300 --> 07:18.370
Let's put the script on the player.

07:19.070 --> 07:21.380
And in the player over here.

07:22.270 --> 07:26.230
And in the player over here, let's type a couple of lines of code.

07:26.260 --> 07:29.260
I promise to you I will explain more in the next video.

07:29.260 --> 07:31.540
As of now, just type after me okay.

07:31.540 --> 07:40.690
So let's do public rigidbody 2d, RB and then in the update over here let's do RB dot velocity equals

07:40.690 --> 07:42.580
to new vector two.

07:42.610 --> 07:46.360
Then we're going to type input get access row.

07:47.090 --> 07:48.560
Horizontal.

07:50.260 --> 07:53.290
And RB velocity dot y just like that.

07:53.290 --> 07:57.550
Only that we need to type type it here, save it.

07:57.550 --> 07:59.620
Then let's go back to unity.

08:04.660 --> 08:08.410
And let's assign rigid body in this field like so.

08:08.410 --> 08:14.380
So now we have a custom component of a player that is responsible for control of the rigid body that

08:14.380 --> 08:16.000
we also have on the player.

08:16.000 --> 08:21.460
And you might see in just now we took RB that we just assigned.

08:21.550 --> 08:22.510
So.

08:24.820 --> 08:30.310
So now this rigid body is basically equals to this rigid body which is.

08:31.670 --> 08:35.480
This rigid body that was created and this rigid body that was controlled.

08:35.480 --> 08:36.050
Right.

08:36.050 --> 08:43.820
And now if we go to play mode and press left or right, we can see how ball moves to the left or to

08:43.820 --> 08:44.510
the right.

08:45.930 --> 08:47.490
Just simple as that.

08:47.490 --> 08:51.510
So this is a great example on how games are made in unity.

08:51.510 --> 08:57.780
You just make a game object, you give it different components, and then you make some custom script

08:57.990 --> 08:59.850
change the behavior of the component.

08:59.850 --> 09:01.920
And basically you have a game.

09:01.920 --> 09:03.780
And now it's a very simple example.

09:03.780 --> 09:08.970
And of course it's a bit more complex than that if you want to make like a playable video game.

09:08.970 --> 09:10.800
But as of now, this is just it.

09:10.800 --> 09:11.760
This is very good.

09:11.760 --> 09:16.050
Now you can see how different components can affect different game objects.

09:16.050 --> 09:17.940
And this is what we're going to do in the future.

09:17.940 --> 09:23.700
Now let's go to the next video and we're going to discuss scripting and basics of C sharp okay I'll

09:23.700 --> 09:24.180
see you there.
