I’m trying to make a script for a light swich so I can turn the light on / off ,but I don’t know where I’m mistaking! The swich has a colider that’s trigged,beacose I want to display a text when you are close to the swich, to show you the key that needs to be presed by you to swich the light. Thank you verry much for the time spend to fix my problem.
/script
using UnityEngine;
using System.Collections;
public class SwichLight : MonoBehaviour {
public bool InTrigger;
public bool LightState;
void Update()
{
if (InTrigger)
{
if (Input.GetKeyDown(KeyCode.E))
{
(GetComponent<Light>().enabled = true);
LightState = true;
}
}
else
{
if (Input.GetKeyDown(KeyCode.E))
{
LightState = false;
(GetComponent<Light>().enabled = false);
}
}
}
void OnGUI()
{
if (LightState)
{
GUI.Box(new Rect(0, 60, 200, 25), "Press E to swich off the light");
}
else
{
GUI.Box(new Rect(0, 60, 200, 25), "Press E to swich on the light!");
}
}
void OnTriggerEnter(Collider other)
{
inTrigger = true;
}
void OnTriggerExit(Collider other)
{
InTrigger = false;
}
}