Made With Unity | Unity VR Part 9: Flashlight
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.
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.
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.
By pressing the trigger, once you are holding the flashlight, you can turn it On or Off the flashlight.
🎮TO BE CONTINUED🎮