O'Reilly logo

UnrealScript Game Programming Cookbook by Dave Voyles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a flashlight to a weapon

Flashlights have been man's best friend to combat darkness since the invention of electricity. A flashlight can even be turned into a weapon, as we saw with 2010's release of Remedy's Alan Wake.

In the following recipe, we'll be creating a flashlight that can attach to the pawn, as well as a weapon, and be toggled on and off with any key of your choice.

Getting ready

Start by creating a new class called WeaponFlashlight and have it extend from SpotLightMovable. Also make it non placeable. Non placeable means that it cannot be dropped onto the map. Essentially it's there to keep things clean for the level designers, and avoid confusion as to how something should or should not be used.

For this recipe, we'll have to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required