Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Components in Unity are very valuable pieces for adding in game play and interactivity. A component is, as the name suggests, part of something. And you're actually already using them. We'll put a component, like we did on the first podium, on the second and third. Selecting that podium object. And choosing either from the top menu Component>Physics>Box Collider, or down on the bottom, picking the last podium, scrolling down and choosing Add Component>Physics>Box Collider.
What we're doing here is adding on a component that dictates some element of game play. In this case, instead of using a mesh collider, because we don't really need to collide with every face of this, we're adding the simplest collider possible. A box collider. Defining the overall volume as something we cannot pass through. And this is easier for the game engine to think about as we're playing. The idea of a component then, is it's a piece of an object or attached to an object that is part of the game play. Components are attached to game objects and we need to think of them in that way.
What makes components neat is that they don't break a prefab connection necessarily. Removing one may cause issues, but adding on a box collider to the podiums is perfectly fine. Now, when I select the podium object, we can see other components on here, such as a mesh renderer and a mesh filter. We've already seen the most basic, a game object, which is simply a transform, it has no other components. And we can add them on as we need. In our components, we have choices we can make over how they behave and what we can do with them and also how to size them, for example, in this box collider, I can put on a physic material, but I'll need to import that package first.
What physic materials do is let this component react like a true material. Is it metal or wood or ice or whatever. And things will slide correctly across it, if need be. In our other components, then, we've got lots of choices to make. We'll look under the component menu and we can add in things like, for example, mesh filters or a mesh render. So we could put a mesh render on our game object for the master building if we actually want to see something. We can add on effects, such as particle systems and trails.
We've got our physics and our physics 2D, new in Unity 3D, which lets us attach physics to objects and also things like joints and hinges, if we want to get into rag dolls and similar rigs and interactions. We can put in things like nav meshes as components on objects, what these let us do is, take NPCs or non player characters and designate areas for them to navigate in. Finally, we can put in audio and there's all kinds of audio filters and zones to add in.
What these let us do is define, for example, an audio zone where maybe we can hear the vents more than in other places. In rendering, we can get into our lights, our flares, additional sky boxes and even our GUIs and a sprite render when we're working in a 2D game. We've got scripts and scripts are a component that's attached to a game object as well. The idea being that a script will very rarely run on its own. At the very least, if there's a script in the game and not connected to an object we need to see, we'll put this script onto a game object and probably put a label on so we can find it.
This way, the script will run maybe when the game starts and judge if something is going on. Finally, there is our character in camera control letting the camera look at things or look around and take input. A lot of these components are already on the first person controller we are using. But these exist if we need to remake in some way or make our own version. So keep in mind then, that a component for us is attached to an object and we can add and subtract them as we need. And add game play and inter activity, taking just standard static assets we've brought in, and really bring some life to them.
I'll add on the last two components here. The bridges, by selecting them and putting on the same box colliders. Here's my last bridge and for this one I'm going to scale that component a bit once its on. I'll choose Component>Physics>Box Collider. This would overlap with the colliders on the podium. So what I'll do is take this box collider on its z axis here and click and drag to scale it in. It's scaling, but not quite fast enough. I'll drag more or just drop down this number.
And I'll pull this collider down so it just matches up with the edge of that podium. A little bit of overlap or underlap is reasonable. As long as it's not a giant meeting. That looks pretty good, and now I can't fall through the bridge. I'll fix this on the other one as well. Selecting the bridge, focusing in, zooming in when focused maybe doesn't quite do it. Choosing Component>Physics>Box Collider, again I'll take the z size of that collider and just pull it in to match.
Many components have their own unique transforms or sizes like this. And so we can attach colliders to multiple objects, and really think about optimizing our collision. What we see versus what we interact with may vary wildly. We may have a lot of boxes we collide with, but they're on complex meshes that really look like the buildings we're navigating around in. I'll give it a quick test play and see how this looks. I've still got to light up this space. It's very gray inside because it's all in shadow. There's my cam lights up at the ceiling and smashing through the doors.
Running outside on the balcony. There's my screens and all their metals. My brick, still a little blown out because I haven't adjusted the lighting. But more importantly, I'm running across the bridge and I'm jumping right through the ceiling. I'm going to smash through the wall and run across the other bridge and into the next building. And through the doors. Okay, I realize this may be just stunningly exciting to see a guy running around on a bridge, but it's really neat to be able to get those components in and start to add in the sense of place by seeing.
Where we can go and limiting, well, the player from falling through the floor.
Get unlimited access to all courses for just $25/month.Become a member
107 Video lessons · 33105 Viewers
94 Video lessons · 22975 Viewers
78 Video lessons · 9323 Viewers
147 Video lessons · 3115 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.