Flash Light

Open World - Scripts - Flash Light

How to make a Flash Light in Unity3D with C#

To make a Flash light in Unity3D its rather simple all you need to do is reference a Light and set it enabled or not and to do this all you need to do is use enabled = !enabled on a key press so if the light is on it will turn off and vice versa.

LightObject.enabled = !LightObject.enabled;

FlashLight.cs 291B

New Input 3.9KB


using UnityEngine;

[RequireComponent(typeof(Light))]
public class FlashLight : MonoBehaviour
{
    public Light LightObject;
    void Update()
    {
        if (NewInput.Instance.RawFire==1)
        {
            LightObject.enabled = !LightObject.enabled;
        }
    }
}
Powered by w3.css