Important Notice:

As of September 15, 2016, we no longer publish new courses on this website. We encourage you to use your Digital-Tutors credentials to sign in on Pluralsight where you'll find all new creative courses, skill tests and paths, 1:1 mentoring and more.
Adding lights
See Details
Joshua Kinney


Joshua Kinney
In this tutorial, we're going to learn how to add and manipulate lights in Unity. All right, so to create lights in Unity, we could do it one of two ways. We can create a game object light by going to Game Object, Create Other. And then choose one of the lights listed in the menu here. Now the first light that we have is directional light. And a directional light are basically placed anywhere in the scene. And they will affect everything in the scene based on the light's rotation. So it's like the sun and the time of day that the sun is at. Now the next type of light that we have is point light. And a point light is basically an omni type of light. So it's like a light bulb, if you want to think of it that way. So it emits light in spherical fashion. We have a spotlight. And a spotlight will emit a light in the shape of a cone. So this is going to be similar to something like a flashlight. And then we have an area light. And an area light is only available for light map baking. This light will shine in all directions to one side of a rectangular section of a plane. So this is like if you wanted to create a light being emitted from a window, or a door, or something like that. So now that we've talked about the different types of lights you can use, let's go ahead and add in a point light. Now doing so is going to bring in this object as a game object itself. So you can see it's separated. And we could actually select it right here in our hierarchy. Now there's another way to creating lights and that's adding a light as a component to an object. So I'm going to bring this light object and I'm going to put in front of this first light here. But we have a mesh over here for our light. And I'm going to add a light to it as a component. So select the light mesh and then go to Add Component, Rendering, and then Light. Here you can see the light is placed right on top of that object. And we can expand the parameters, so we could begin to adjust those parameters. Now the parameters in the component and the game object are going to be exactly the same. So let's go ahead and select the point light game object in our scene. And I'm going to go ahead and just run through these parameters with you. So we have type. So whenever we add a light into our scene, if we decided that the point light is probably not going to be best, instead of deleting it and adding a new light, we can simply just change its type to something like spotlight if we wanted to do that. I'm going to go ahead and change it back to point light because that's going to be the desired light that I want for this object. Now we have range. And the range is going to affect the overall distance, or radius, the light is going to be effective in the environment. So if I bump this up to 15, you'll notice that the light radius becomes larger. And we're affecting more in the scene. The next parameter that we have is our color. And if we select that color swatch we can go ahead and pick any color that we want in our scene. Now you also have the ability of using this eye dropper and picking a specific color that's already in your scene. So I'm going to go ahead and just use my color picker here. And I'm just going to choose an off-white, orangeish color. And then hit OK. Now underneath that we have our intensity. And this is just going to adjust the overall brightness of that light. So getting much higher than that is going to really blow out the scene here. So we want to stick to around one or less. Now, in this case, I'm just going to type in 0.8. And then hit Enter. Below intensity we have cookie. And this allows us to add a texture to our light. And what this does is it basically mimics a shadow in the shape of the texture that you're using. So in this case, we could use a texture that is black and white. And it's in the shape of a window. So the window panes themselves would be a white color. And then the slats in between the window panes would be a black color. So what it will do is emit that shape as a shadow from our object. We have shadow type. And in this case, we want to go ahead and change our shadow type from no shadows to hard shadows. Now, you may be getting a little bit of a warning here. And that's because, by default, Unity uses what's called forward rendering. If you want to be able to use shadows on your lights what you'll need to do is go to Edit, Project Settings, and then Player. And in here you'll see your rendering path. You'll want to switch that from forward lights to deferred light. So this is what it looks like by default. If I select that light, you'll see that warning here. So let's go ahead and switch that back. Project Settings, Player, and then switch it from forward to deferred lighting. All right, so now that we have discussed that, we have some shadow options here. So we can change it from hard shadows to soft shadows, or we can adjust the overall strength of our shadows. Now I'm going to take this back a little bit. I'm going to take light and I'm going to push it back toward the light source itself so we can see some of these shadows a little bit easier. And I'm going to go ahead and try to align that a little bit better to our object. There we go. And you could see the shadows along the floor. Now, if we adjust the strength what it's going to do is adjust the overall opacity of our shadow. So if I draw that down, you'll notice that our shadow becomes lighter and lighter until it becomes non-existent. So normally, in an area like this where there are very few lighting sources, we want to go ahead and make sure that the strength of our shadows is set to one. Now we also have resolution. And normally, what we want to do is we want to use the quality settings. So we want to leave that up to the player's machine to adjust the overall settings of that. We have draw halo and flare. And these are basically post-processing affects to where if we can create light flares and lens flares on our lights themselves. And you can do that by adding a flare object. We're not going to discuss that in this course because it's not something that we really want to do. We also have our rendering modes. And we want to set this to auto for our lights. We have culling mask. And normally, if we have a light selected, if we want it to affect only certain objects, we will set that certain object on a layer. And then we will ignore everything else. Now in this case, we want our light to affect everything. So everything is checked here. And then finally, we have light mapping. And it's basically going to determine if this light has been baked. And in this case, we haven't baked any lights, but we will talk about how to do that later on. Now the final thing that I want to talk to you about is taking this light and making it part of a mesh, so that way we can quickly create lights throughout our scene. Because it would be very difficult to go ahead and create a light and then drag on a light source itself and trying to line that up. So that's the advantage of using a light with a component. However, the disadvantage of using the light as a component means that the light is centered on that object. And we cannot change the overall position of that. So you can see here that the lighting is much different than over here. This gives us a lot of flexibility. So with this light mesh here, I'm just going to go ahead and just delete it out of the scene. And we're going to use this. Now to do this, what we want to do is we want to create a prefab for this. So I'm going to take my point light here and I'm going to drag that right on top of my light object so that way it's in there. And I'm going to rename this light object to pfb_walllight. And then I'm going to create a prefab by right clicking, Create, Prefab. And let's call that the same thing, so pfb_walllight. And then we'll drag and drop that object right on there. So with using this prefab, what I can do is go ahead and hit Control D to duplicate that. And I can move it across this wall here. And I still have the flexibility of moving the individual light itself. And I could even come in and change its overall color. So if I want to just change this to something like a blue color, I could do so without worrying about changing the other object as well. So everything is looking pretty good here. And you can do that as much as you like. You don't necessarily have to stick to one color on your lights themselves. All right, so now that we've talked about lights and how to manipulate them and the different ways that we can add them to an object, what I want you to do in between lessons is go ahead and set up some lighting throughout your level. And you don't have to use just this wall light. You can even add in just some lights that are going to just to help the overall look of your level. And you could add things like glowing sections, maybe it could be from mushrooms, or glowing fungus, or something like that. And you could just add a little point light in an area. And change its color. So just have fun with really bringing your level together with lights. So in our next lesson, what we're going to do is we're going to have those lights in our scene. And then we're going to learn about light mapping and how that is going to affect our game.
In this series of Unity tutorials we are going to learn about the core features in Unity.

We will start out by learning the Unity Interface where we'll talk about the different panels and tools available in the Unity editor. From there we'll learn how to properly export and import assets into Unity. With those assets imported, we'll discuss how to create prefabs that will help us speed up the construction process of our level.

Then we'll learn how to create and apply materials to our level prefabs. Then we'll take our textured prefabs and build a simple game environment. Once the base level has been built, we will talk about adding props and set dressing our level. From there we'll continue full speed by learning how to add lights, particles, and physics objects.

Once we're happy with our level, we'll jump into scripting in Unity. We'll learn how to create a random player spawn, a HUD, item pickups, and so much more. Finally, we'll end the course with how to publish our game to the platform of our choosing.

For an additional learning resource, download your free copy of our Key Game Development Terms Reference Guide and PDF so you can get comfortable with important game dev terminology.