Hello,
so I created a basic script that when “e” is pressed down the light specified turns on, then off again if you press it again. For some reason though the light doesn’t always turn on when “e” is pressed and I have no idea why. Here’s my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightsOnPress : MonoBehaviour
{
public AudioSource Click;
public Light Lights;
public GameObject Text;
public bool LightisOn;
public void Start()
{
LightisOn = Lights.enabled = false;
}
void OnTriggerStay(Collider other)
{
Text.gameObject.SetActive(true);
if (Input.GetKeyDown("e"))
{
if (LightisOn)
{
LightisOn = Lights.enabled = false;
Click.Play();
}
else
{
LightisOn = Lights.enabled = true;
Click.Play();
}
}
}
void OnTriggerExit(Collider other)
{
Text.gameObject.SetActive(false);
}
}