Hello guys.
Welcome to the video.
In this one I want to tell you about very important aspect of development and that is components of
unity.
So for now I'm going to delete this full image over here.
Let's delete it.
And let's just click right button and click Create Empty.
So now we can see we have a game object that is empty.
And it has only one component transform.
Transform cannot be removed.
It is there by default.
And transform is needed to define where object is in the world, what is rotation and what's his scale.
That is very important.
So transform is a component, and there are other components that we need to give certain properties
to the game object or set certain behavior on the game object.
We can imagine like you know, game object is like a car, for example.
And just as a car has different parts like engine wheels, lights, and each part gives different functionality
to the car, same way components give different functionality to the game object.
As example, we have an empty game object and it does nothing.
It is just there.
But let's say we create 2D sprite square.
We can see that this square has a transform, same as the previous one, but also it has a sprite renderer
and this one responsible for the visuals of this game object.
Now that we know that this square looks like this because it has sprite renderer, uh, let's change
color of this square.
To something darker and let's just rename it.
To platform.
Okay.
Now I'm going to select this platform.
Press move tool.
Move it down.
And then I want to stretch it just like so.
So now we created a game object platform I'm sorry for the name.
Yeah.
So now we created a game object that is platform, and it has the dark blue color and it has this shape
because we changed the scale on the transform.
Now we can create another object.
Let's do 2D sprite circle and let's name it as player maybe okay.
So now we have another game object in the game that has very similar components.
And we want player to behave in a certain way.
For example, we want this player which looks like a ball to fall when we play the game.
We want it to be affected by gravity.
How could we do that?
Well, we could achieve that by adding new component to this game object.
Let's go over here and click Add Component.
And here you can see we have so many components, so many different things, but we're going to discuss
them as we use them.
So don't worry about everything.
Just type rigidbody in the search field.
And here we need to choose 2D because we work with the 2D objects.
Let's click 2D.
Now this object not only has visuals of a circle of a white color, but also it has a rigid body and
that makes it behave like an object, like a physical object in a game world.
If we select here, play focus so it will not open full screen and go to play mode.
You can see that player now is falling down.
So we change the behavior of the object by adding a component.
And game development is just about that.
You take an object, you give it different components and define how you want it to behave.
And you set this behavior with a component that you put on the game object.
Also, there is a way to create custom components.
We call them scripts.
They are just behavior as we need.
But as of now let's just try to do something else.
Let's say we have this ball falling and we like it, and we like how it looks, but we don't like that
it is falling through the platform.
That happens because unity does not know what is the shape of the object.
It knows how it looks, it knows it's supposed to fall, and it's supposed to be affected by gravity,
but it doesn't know what is the shape, where is the end of the object?
Maybe just like that.
Maybe it's just like that.
Unity doesn't know.
So we have to add another component to tell unity, hey, this object has this shape, and shape is
usually defined by the colliders that we put on the object.
So let's click Add Component.
And because this is a circle over here we can just type circle Collider 2D.
And let's just choose it.
Now.
By default it will take the shape of the sprite, but if we would want to make it bigger, we could
choose Edit Collider and Stretch Collider to the size we want.
However, we don't want to stretch Collider right now.
It is okay, so let's just click reset and it's going to be default as it was before.
And now let's go to the play mode and see if ball will be stopped by the platform.
And no, it fell through the platform.
Same as before.
Why is that?
Well, that is very simple.
You need to knows what is the shape of this object.
You need to know what is the collision should be for this object.
But you need to know nothing about collision on this platform.
So we have to add component here.
And for example type box collider 2D.
Now again it will take shape of a sprite.
So we don't need to edit anything here.
And let's just go to play mode right now and try it out.
And boom ball is falling on the platform.
Very cool.
So believe me or not, this is already a game.
In fact, we could do something here.
Let's, um, let's click right button create and we need to find 2D physics material 2D okay.
Let's just call it matte for now.
I'm going to exit play mode because when you do changes in the play mode they are not saved.
And here on the material, let's add Bounciness here.
Let's just make it maybe as one.
And then let's take the player and drag this material on the collider.
And let's go back to the play mode.
And now we can see ball is jumping.
Very cool.
Right.
We can take the platform and play tennis.
You.
Yeah.
So this is how you use components and components properties to change behavior of game objects.
I'm going to delete this material.
We don't need it anymore.
It was just an example.
And remove it from here.
Now these are components that are predefined by unity and we're going to use them a lot.
You can also make custom components and that is very easy to achieve.
We can create C sharp script let's call it player for example.
And with the help of this custom script we can adjust behavior of the object just as we want.
We're going to talk more about basics of programming later on in the course, but for now, let's just
try this.
Let's put the script on the player.
And in the player over here.
And in the player over here, let's type a couple of lines of code.
I promise to you I will explain more in the next video.
As of now, just type after me okay.
So let's do public rigidbody 2d, RB and then in the update over here let's do RB dot velocity equals
to new vector two.
Then we're going to type input get access row.
Horizontal.
And RB velocity dot y just like that.
Only that we need to type type it here, save it.
Then let's go back to unity.
And let's assign rigid body in this field like so.
So now we have a custom component of a player that is responsible for control of the rigid body that
we also have on the player.
And you might see in just now we took RB that we just assigned.
So.
So now this rigid body is basically equals to this rigid body which is.
This rigid body that was created and this rigid body that was controlled.
Right.
And now if we go to play mode and press left or right, we can see how ball moves to the left or to
the right.
Just simple as that.
So this is a great example on how games are made in unity.
You just make a game object, you give it different components, and then you make some custom script
change the behavior of the component.
And basically you have a game.
And now it's a very simple example.
And of course it's a bit more complex than that if you want to make like a playable video game.
But as of now, this is just it.
This is very good.
Now you can see how different components can affect different game objects.
And this is what we're going to do in the future.
Now let's go to the next video and we're going to discuss scripting and basics of C sharp okay I'll
see you there.