Flashlight toggle light On/Off
In one of my previous posts I've added the Flashlight unity package Prefab and resources used but I didn't added the functionality, the script to toggle Flashlight light on/off.
This is a C# script for Flashlight prefab mentioned in a previous post.
Github
Step by step suggestions on how to use the script.
First of all make sure you have downloaded the Flashlight prefab, its important to have the GameObject so you can assign the C# script to it.
I've used the flashlight game object assigned as child to FPSController > FirstPersonCharacter (main camera).
With FirstPersonCharacter selected, drag the flashlight game object under it as a child (you'll notice the small triangles in Hierarchy, next to object's name).
Final step is to assign the last Spotlight in the Inspector window under the script. See the screenshot below.
One more thing... as you can notice, the key for switching the light on/off is F on your keyboard . Editing the C# script you can assign other key of your choice.
Quick note. If you want the flashlight to be default as off you can disable the light component check/un-check box and it will be active when F key is pressed.
Comments
Post a Comment