How to Create a Flashlight Mechanic in Unity 3D for Horror Games
- Krishnamohan Yagneswaran
- 2 days ago
- 2 min read
Introduction
Want to add tension and realism to your horror game? One of the most immersive features you can add is a flashlight mechanic. A working flashlight not only enhances visibility in dark scenes but also adds suspense as players rely on a limited light source to survive terrifying encounters. In this beginner-friendly tutorial, you’ll learn how to create a flashlight in Unity 3D using simple C# scripting—perfect for horror game developers who want to build immersive experiences.

Step 1: Setting Up the Scene
To begin, open Unity and create a new 3D project. Set up a basic scene to test your flashlight mechanic:
Add a Plane for the ground.
Add Cubes or other 3D objects to simulate obstacles.
Create a Directional Light and dim it or disable it for a darker environment.
Step 2: Create the Flashlight
1. Add an Empty GameObject
Right-click in the Hierarchy panel.
Select Create Empty, name it Flashlight.
2. Add a Light Component
Select the Flashlight GameObject.
In the Inspector, click Add Component > Light > Spot Light.
Adjust the Spot Angle, Range, and Intensity to match a flashlight feel.
Set Shadows to "Soft Shadows" for realism.
3. Position the Flashlight
Make the flashlight a child of your player’s camera (e.g., Main Camera) so it moves with the player’s view:
Drag the Flashlight GameObject onto the Main Camera.
Step 3: Add Flashlight Script in C#
Create a new C# script to toggle the flashlight on and off with a key press.
📄 Script: FlashlightController.cs
using UnityEngine;
public class FlashlightController : MonoBehaviour
{
public Light flashlight;
public KeyCode toggleKey = KeyCode.F;
void Start()
{
if (flashlight == null)
flashlight = GetComponent<Light>();
flashlight.enabled = false; // Starts off
}
void Update()
{
if (Input.GetKeyDown(toggleKey))
{
flashlight.enabled = !flashlight.enabled;
}
}
}
How to Use:
Attach the script to the Flashlight GameObject.
Drag and drop the Light component from the GameObject into the script’s Flashlight field in the Inspector.
Step 4: Optional – Add Battery Life or Flickering Effect
Want to make the game more intense? Add features like:
Battery Drain Over Time
Flickering Light Effect When Near Enemies
Randomized Light Cut-Off Events
Let me know if you'd like a script for those too!
Final Thoughts
Flashlights are a staple in horror games for a reason—they limit the player’s vision, add immersion, and create tension. With this simple Unity setup, you’ve now built the foundation of a powerful horror game mechanic. Continue enhancing your flashlight by adding animations, sounds, or visual effects to take your game to the next level.
🛑 Disclaimer: This guide is based on Unity 2022.3 LTS or newer and may vary slightly with future updates.
☕ Support My Work
Found this guide useful? You can support my content by buying me a coffee:👉 https://krishnamohany.gumroad.com/coffee
📘 Learn More with This Book
Grab this Unity 3D paperback for beginners and start mastering your skills:👉 Unity Paperback (Affiliate)
Comments