What you will learn
In this Unity tutorial, we will learn how to effectively utilize the game engine. Over the tutorial, we will learn how to use the Unity editor interface as well as how to navigate in the scene view. From there, we will learn how to import assets and how to create prefabs. Then we will shape our level even more by adding character controllers, colliders, lights, materials and physics. We will then finish the tutorial by learning how to use scripting in order to make our level interactive.
In this lesson, we're going to learn how to create lights inside of our Unity game level. OK, so let's go ahead and create some lights in our level so that way, we can actually see the level. So let's go ahead and just move over the top here. And what I'm going to do is I'm actually going to create some lights that go throughout each hallway and in each room. So I'm going to switch to my top view just by clicking on the y-axis on our scene gizmo. And what I'm going to do is create a point light. Now, I can do this a couple of different ways. I could go to my hierarchy and create a point light that way. Or, I could go up to Game Object and then create a point light that way. So I'm actually going to use the game object menu here. So I'm going to Create Point Light. And what I'm going to do is basically just put this in each room and then all the way around the hallways here. Now, to do this, I'm not going to go ahead hit Game Object, Create Other, and then Point Light every single time. I'm just going to go ahead and duplicate this one and then place it. So let's hold down Control and hit D, and let's just place these roughly where we want them in our scene. So I'm going to keep hitting Control D just to duplicate this, and then moving them to points in my level here. And I know this is going to be a tedious portion of the video here because we're just doing the same thing over and over again. We're just going to place things all the way around because we want to make sure that our level is going to be lit enough to where we can actually see what we're doing. And then, we'll get into actually play testing it, checking all of our walls for collisions, and we'll actually talk about making those collisions in our next lesson. OK, so I have all of our lights here. Let me create one more and put it right up in this room here. All right, so let's switch over to our perspective view. So on your scene gizmo, just click on that yellow box. And you'll notice that our lights are completely below our level here. So what I can do is go ahead and use a box selection. So just click and drag, and select your lights. So let's go ahead and drag these up into our scene. And now you can see that this is lighting up our level quite nicely now. Now, you could bring them all the way up to the ceiling if you want to, or just a little bit below it, really doesn't really matter. We're just trying to get a look at our level and see what it looks like here. Now, one really neat feature that we have here whenever we have these lights up. Sometimes these icons and gizmos can get in the way. So a great way to help you view the scene view a little bit better is we can actually go to the gizmo section here and actually update or modify the way our icons and gizmos look inside of our scene view. So right now, we have our lights. And I can actually turn off those icons, or I can turn off the gizmos, OK? Or, I could turn off both at the same time. Our lights are still in there. They're just been hidden at the moment. So I'm going to go ahead and bring those gizmos and that icon back. And if I want to, I can even just take down the scaling of those icons, make them a little bit smaller. Now, I like them to be a lot larger because whenever I'm trying to select those, the larger they are, the easier they are to select. Now, the gizmos are not going to show up unless they're actually selected. So if we deselect, those gizmos are going to go away, OK? So this is really not that big of an issue. Now, whenever we start getting into audio and we start bringing in these different components, then I might want to start hiding some of those different icons. OK, so we've brought in our point lights. So let's actually talk about how we can control these lights. So I'm going to select a single light right here in this room here. And let's go to our inspector and take a look at our light options. So in our inspector, we have our transformation data. And this is basically where it is in 3D space. We can rotate it if we want. And we could even scale this up. Now, this is only going to scale the icon itself. So we're just going to leave that the way it is. Now, if I want to actually scale the range of my light, that's what I actually have right here. So I can take this from 10, and I can click and drag this up. And this will make my light go out further. Or I can scale it down and make it a little bit dimmer. Now, this is not actually changing its intensity. It's just changing how much it can affect. So I'm going to stick with 10. So I'm just going to type that in there. I just think that's a pretty good size to start out with. Now, the next thing that we can change is our color. So if I'm looking for a light that's actually supposed to be, let's say, an alarm, or a siren, or something like that, I could change this to a red color. Now that I've got that in there, I can go down to my intensity. And intensity is just going to basically affect the intensity. It's pretty self-explanatory. So if I take this up, it's going to get much brighter. If I take it down, it's going to get dim. And if we go down to 0, it's completely off. So let's go ahead and take this back down to 1, just a default value. And we can actually go ahead and put a texture on this. And it acts like a projector. Now, we are working with a point light. So this cookie is not actually going to work with our point light. It only works with directional lights. So let's go ahead and go to our shadow type. And we can actually tell this light what type of shadows it should be creating. So we could do hard shadows, and we could do soft shadows. Now, because we're just using the free version for this specific edition of our courses, we're not able to actually use the soft shadows or hard shadows. So we can only do this whenever we are in our Unity Pro. So let's go ahead and go to no shadows there. Now, we could draw a halo around this light here. If we check that, you'll see that this gets much brighter and very intense to a point. And it actually creates this halo effect. So let's go ahead and close that. We could apply a lens flare to this if we want to. Now, I don't actually have any lens flare assets for this, so we can't actually apply that just yet. Now, we have our render mode. And we have audio, important, and not important. And this basically means that we're setting up our rendering method. So by default, it's set to auto. And basically, this rendering method is basically determined by the run time depending on the brightness in nearby lights. So it's going to work off the quality settings whenever we do our build. Now, if we set this to important, this light is always going to be rendered per pixel quality. So we're going to get a really nice effect on this. So if we're going to use important, we probably want to do this if we're creating headlights on a car or something like that. Now then, we have not important. And this light is always rendered in a faster vertex object light mode. So this is going to be very, very quick and it's very easy. So what I'm going to do is go ahead and switch this over to automatic. Let me actually click on the right one there. And now, we have culling mask. And this basically allows us to exclude groups of objects from actually being affected by this light. So I want my light to affect everything. so I'm going to go ahead and actually keep this on. Now, I have my light mapping. And we're setting this to auto here. Now, we're going to go ahead and talk about light mapping because this is a great way to save memory on your computer and on your actual project. So what light mapping is going to do is actually take the current lights that you have in your scene and build a texture map for each object in your scene. Now, one important note-- whenever you are actually going to bake lights onto your objects or use this light mapping technique, you need to make sure that all of your objects are UVed and there are no overlapping UVs. Because what you're going to get is you might get some odd shadows if you have some overlapping UVs. Now, I went ahead and I overlapped some UVs just so you can see those areas whenever we actually bake these lights in. So let's go ahead and do that right now. So let's go to our Window and bring up the Light Mapping window. OK, now you'll see here that I have an object selected in my scene. And under my Object tab, it's actually going to go ahead and show me my options of my selected object. So in this case, I have a light. And I can actually adjust my color, my intensity, its light mapping method, and even some bounce intensity here. And I can even tell it if I want to bake in some shadows. And I could use the real time hard shadows or soft shadows. Now, because we're using this free version, those aren't available. So we're just going to leave that as off. Now, what I want to do is actually just create an entire set of light maps for everything in my scene. So I'm going to go ahead and just deselect everything. And I'm going to go ahead and his just hit Bake on this. Now, it's saying that there's nothing to bake. And the reason that this is, is because all of our objects that are in our scene are actually not static. Let me show you what I mean by that. So if I hit OK and I select one of my objects, my pre-fab here, you'll notice that in my inspector, I have this little check box that says "static," and it's been unchecked. So if I want light mapping to work properly and actually map these specific objects, I need to set all of these to Static. So what I'm going to do is I'm going to go ahead and check this. And it's going to give me a dialog box that says, "Change is static. Do you want to make the object and its child object static?" And I want to make it easier for myself. So I'm just going to hit "Yes, change children." And I'm going to go all the way around and select each object and do that. So I'm going to go ahead and pause the video, and then you can do that in the meantime there. OK, so I've gone ahead, and I've selected all of my objects and applied those to static. You may have had to go through one at a time and do that. So that's just one of those tedious processes that we have to go through. So once all of those are set to static, what we can do is go ahead and just bake our objects. So I'm just going to make sure that everything is deselected, and I'm just going to hit Bake. Now, you're going to notice that we have a little bar that comes up here at the bottom saying it's baking its textures. Now, we could still go ahead and we can move around in our scene, and we can still do a little bit of work. But what we want to do is go ahead and just let it bake. So I'm going to pause the video and then come back whenever this is finished. OK, so now this is finished baking our maps. And you can see in our preview window here that we have two sets of maps. We have a far set and a near set. And this is because of our dual maps that we have set up whenever we bake this. So we're in dual light maps mode. Now, I can't get real in-depth with what far and near means, because then we have to start talking about what render paths are, OK? So, it's gone ahead and created our light maps. And these are textures. And these textures have been applied to our materials here. And what we can do now is actually go ahead and close out our light mapping and delete all of these lights. And we'll still have the same look here. So let me just go ahead and show you by example here. So let's select one of our point lights, scroll down in our hierarchy, hold down Shift, select those point lights. And what I'm going to do is just hit Delete on my keyboard. Now once that's done, you'll see that our lights still look like they're there. So what we've actually done is baked those lights into our textures and saved a ton of memory. So now, it looks like we can move around in here and work with the lights. Now, what I'm going to do is go ahead and just look at our light map and just check this out. Now, you'll see that we have a couple of areas that we have some shadows. And this is because of some overlapping in our UVs. So I do want you to be careful of that. You've got to make sure that your UVs are done right and complete, and there's no overlapping. So I just wanted to show you that problem area. Now, I want to get rid of that. So what I'm going to do is actually hit Control Z one time to bring back my lights. And I'm going to bring up my light mapping window again. And I want to show you a way that you can just get rid of these light maps if you're not happy with it. And it's as simple as just hitting Clear. And now, those light maps are now gone. So now, if I go ahead and turn off these lights here, you'll see that we no longer have those textures. All right, so we have talked about how we can control lights in this lesson, and how we can actually get into light mapping. And in our next lesson, what we're going to do is actually add some materials to our level to start making this look a little bit better and looking really, really nice. So let's go ahead and end this video here. And I'll see you in the next lesson.