GameObjects and Components

Transcript

English (Auto-generated)

Hi everyone in this cast, we'll be talking about game objects and components. So these are the building blocks of your game and they're pretty important. Now, a game object is a collection of components such as the transformed component, rigid body component and so on and so forth. So for example, let me make a three D cube and you can either do this by going to game object here and then in the menu bar and then going down to three D. Object and clicking on cube. Or you can right click in the hierarchy window and scroll down to three D. Q. Object and then click on Q. So out here you can see that it has created this cube for me in the center of my scene. And let's take a look at this. So like I said that game objects and components go hand in hand. Game objects are the building blocks of a game scene and anything that is part of the game scene is a game object. So in an empty scene you have the main camera and directional light. Game objects which are added for you by default and are seen out here on the left side in the hierarchy window, you can see we have all these game objects which are part of our scene, including the camera that you can see here. So this bit here and then we also have a directional light which is well not this, this is the lantern. We also have a directional light component which should be somewhere here. Okay, and there you go there. It is. That's a directional light component out here. Okay, so now Coming back to our three D Cube here. Right? So you can see that our three D. Cube has all these components to it. Right? So it has this cube, this mesh filter, it has a mesh render. We have a box collider and we have this default material which is basically just the color of the cube. Right? The material. So now looking at all these components on the right side in the inspector panel we can give a definition to a game object. So a game object is a container. Four components. Right? With some common properties and functionalities. So you can add components to a game object. You can also delete components from game objects and all these game objects in your scene will have some common components. So for example I can delete let's we can delete the box collider by clicking on removed component. Right? Which will remove the component for us. There you go. And if I want to add it again I can click on add component and then box collider. So it's added the component for me. one of the common components in all game objects is the transformed component which has position, rotation and scale properties. So you cannot. This is common in all game objects and basically you can't remove this component. If you right click, you'll see that you cannot remove the component. Okay, so coming back to our cube object, I'm just going to click on it and then let's take a look at all its components out here. So some common properties are first we have this active checkbox right? Which is going to allow you to set the active state of a game object. So now my game object is active. If I click here, there you go, it's deactivated and it's been removed from the scene and if I click on it again it's active. And then we have this name text box which is going to allow you to set the name of your game objects. You can type anything in here and then we have this static check box which is going to allow you to set the game object as active or ecstatic. We also have a tag out here so you can add your own tag or choose an existing attack. Um attack is going to allow you to basically tag or you know, give your game object some identify it so that you can access it in your script. So that's a common use case for a tag. And then we also have this layer drop down which is going to allow you to set the layer in which the game object will be placed. So it could be in the transparent effects clear or you could just be in the default clear and I believe there's about 32 of these. We can check 30 Yeah, 32 because it starts from um layer zero. So there's are useful for example, if you're making a game with lots of collisions, some game objects might collide with other game objects that belong to a certain layer. So that is one news case for the layer and then these are some common properties. Right? So let's look at this cube game object and you'll see that it has a mesh filter measure, surrender and box collider component. And we also have this default material. Right? So out here we have like I said, measure render. So let's talk briefly about these components. So mesh filter component. Uh this is going to define the geometry or form of a game object. So for example the cube mesh filter is going to tell the unity is going to tell unity that the shape of this game object is a cube. Right now we have a mesh render component here. And this component is going to render the geometry or mesh based on the mesh filter. So that is the mesh render tells unity how to display the object. We also have a collider component. Now this is going to define the geometry for physics collision. So it's going to define the physics collision shape. And the collider is used for three D. Physics and unity is going to keep objects with colliders on them from passing through each other. So we can also make our own game object. So for an example you can either go up here and create empty or in the hierarchy window you can right click create empty. Okay, so this is my empty game object, which you cannot see right now. But let's make it a cube. So you know by default that every game object even empty game objects have a transformed component. Right? And it's telling us that this is the position in X, Y and Z coordinates. It's not in any rotation. And the scale is 111. Okay, so we can add a mesh filter component. Right? There it is mesh filter. And then we need to choose what kind of mesh filter this is because remember that mesh filter defines the geometry of a game object. So let's tell unity that this is going to be a cube or a sphere, anything that you want, it can even be a capsule. Right? So there you go. I've chosen capsule. And then we also want to give this a mesh gender. There you go. Right, So that's my capsule. And then remember we also have a collider on here and it's going to be a capsule collider. Right? So that is my capsule collider. So now we've made a capsule game object from scratch. Now, if I play the game, you'll notice one thing um you'll see that my objects are suspended in the air. And if we want them to fall to the ground, we have to add another component, which is called rigid body. So this is another component that we've added. And rigid bodies are components which are going to allow a game object to react to real time physics and this means it's going to react to forces like gravity mass, momentum. So now if I click on lee you'll see that my capsule has fallen to the ground. My cube is still suspended in the air. So you could also add a rigid body component to the Q. And now let's go ahead and check this out. Okay so now you see, oops what happened there? Did I not add in my mesh render no rigid body? The component because already contains the same component. Okay let's go ahead. Okay so it seems that um I'm trying to see where my mesh rigid body is here. So rigid body is there and it should be falling to the ground. So I can also change the mass. So for example I could say this is five uses gravity collision detection, discrete. Well let that be let me actually remove and add this component again. Rigid body and it's on the cube. Yes it is. So let's see mm mm Is it active? It's static. Ah there you go. So it was tagged as static. We had to you know uncheck mark this static check box right here to the far right in the inspector window. So it's not static here in the in our uh sorry capsule or game object. And it was static cured, which is why it was not reacting to our physics. Okay. So you can either make a game object in the hierarchy window and you can also make it from up here in the menu bar by going to game object. So we have a ton of built in game objects besides these primitive shapes like cube um sphere capsule playing etcetera. You also have game objects under effects. For example, particle system trail line, you have light game objects. So out here we have a directional light, a point light, a spotlight area light. So there's different types of lights that you can use. For example, maybe you just want a point light because you're highlighting a certain area in your game where a player has to go and pick up coins or some kind of collectible. We have audio, video Ui components and we have our and the Ui you'll see text text mesh pro. So don't be confused. A text mesh pro is a replacement for Unity's older text mesh just because it's responsive and is going to react to different screen sizes. So we have a camera component. You can add more than one camera. We already have a default camera object but you can certainly add more cameras if you want. So a whole bunch of components and they're you know on per use case basis. You don't have to use them all at once. And if we wanted to add a material to our um, to our cube object, what you can do is I'm in the materials folder, right click create and then let's see material and I'll just call it cube and then out here let's change the color, right? Let's just say it's maybe blue and then drag and drop here, right? So I can drag and drop on the my capsule game objects and my cube game object. And that's how basically you add some solid color to your game objects and as you can see both of them are reacting to gravity and they fall down. So that's all for this cast and in the next case we'll do a bit of scripting.
52 Views 0 Likes 0 Comments

GameObjects and Components in Unity are the building blocks of your game and are important since everything in a Unity game is a game object including

Comment
Leave a comment (supports markdown format)