Made With Unity | Unity VR Part 9: Flashlight

Rehtse Studio
3 min readAug 6, 2022

Let's add a simple flashlight mechanic to our scene so our VR player can interact with it.

Getting The Flashlight

Using Filebase I download a simple flashlight asset and added it to my Unity scene

In Unity, this asset has the following component: Rigidbody, Mesh Collider, and the XR Grab Interactable.

As has been shown in this series of articles, the XR Grab Interactable is the component that is going to allow us to interact with the object in VR.

Creating Light

Add a Spotlight game object as a child to our Flashlight asset

Play around with the Spot Light settings in the Inspector

Flashlight Behaviour Script

Create a new script, named it FlashlightBehaviour, and added it to the Flashlight game object.

On Unity, drag the Spot Light from the Flashlight and place it on the field Flashlight Light OB.

Interactable Events

Back to the Flashlight, locate the XR Grab Interactable component, locate Interactable Events and go down the many events list and find the Activate [Activated(ActivateEventArgs)]

Press the plus sign and drag the Flashlight object to the None (object) empty field. Press where it says No Function and locate the FlashlightBehaviour script.

Select ActivateFlashlight(), is the public method we created on the script.

Press Play

By pressing the trigger, once you are holding the flashlight, you can turn it On or Off the flashlight.




Rehtse Studio

Game Developer sharing content around Unity, programing and tips and tricks in game dev.