Toggle light by pressing e

here is a script for toggle light with the e key:

using UnityEngine;

public class LightToggle : MonoBehaviour
{
    // Reference to the Light component
    private Light myLight;

    // Get the Light component from the GameObject
    void Start()
    {
        myLight = GetComponent<Light>();
    }

    // Update is called once per frame
    void Update()
    {
        // Check if the 'E' key is pressed
        if (Input.GetKeyDown(KeyCode.E))
        {
            // Toggle the light on and off
            myLight.enabled = !myLight.enabled;
        }
    }
}

you can change the sensitivity of the light

You didn’t give enough description of the problem so we can help you, but I can tell:

  1. Make sure that the script is attached to the object with light
  2. Make sure that the light.enable is true before you try to turn it off
  3. Put one more GetKeyDown for light.enable to be on, so it’s easier to debug.