Adding a flashlight

Now that we have a player, we can start creating some custom behaviors for them. Our level currently looks like a dark night, but we still want to give our players the ability to see what's in front of them with a flashlight. We will customize the FPS Controller object to fit our needs:

  1. Create a spotlight by navigating to GameObject | Light | Spotlight. Once created, we are going to make the spotlight a child of the FPSController object's FirstPersonCharacter object by dragging and dropping it on top of it.
    Adding a flashlight
  2. Once this is done, change the Transform Position value to (0, -.95, 0). Because positions are relative to your components position, this places the light slightly lower than the camera's center, just like a hand holding a flashlight. Now change the Rotation value to (0,0,0) or give it a slight diagonal effect across the scene if you don't want it to look like it's coming straight out:
    Adding a flashlight
  3. Now, we want the flashlight to reach out the distance. So we will change the Range value to 1000, and to make the light wider, we will change the Spot Angle value to 45. Finally, we can change the Shadow Type to Hard Shadows so the light will cause shadows behind objects that it hits. The effects are shown in the following screenshot:
    Adding a flashlight

We now have a flashlight, so the player can focus on a particular area and relax.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset