- Home /
Question by
Sveyh · Mar 28, 2014 at 12:24 PM ·
triggerlightunity input
OnTriggerEnterinputLight
Hello, I've created a script (it works though) which is for a trigger light on input, and the thing is, when I wrote this script I never managed to put the same input button for the light to turn on or off, its 2 diffirent buttons. And what I want is one SINGLE button for On and Off, anyone can help me out with that?
{
public Light taklampa;
private bool Sam;
private bool text;
// Use this for initialization
void Start ()
{
taklampa.enabled = false;
Sam = false;
text = false;
}
// Update is called once per frame
void Update ()
{
if (Sam == true && Input.GetKeyDown (KeyCode.E))
{
taklampa.enabled = true;
}
else if (taklampa.enabled == true && Sam == true && Input.GetKeyDown (KeyCode.T))
{
taklampa.enabled = false;
}
}
void OnTriggerEnter(Collider other)
{
Sam = true;
text = true;
}
void OnTriggerExit(Collider other)
{
Sam = false;
text = false;
}
void OnGUI()
{
if (text == true)
{
GUI.Box(new Rect(350, 100, 400, 100), "Press E to Turn On & T to turn Off");
}
}
}
thanks in advance.
Comment
I'll move it to answers so you can mark it as correct :D Stoked it helped.
Best Answer
Answer by Destran · Mar 28, 2014 at 12:49 PM
I'm not actually sure if this is valid but you could try:
if (Sam == true && Input.GetKeyDown (KeyCode.E))
{
taklampa.enabled = !taklampa.enabled;
}
Your answer
Follow this Question
Related Questions
flickering lights when player gets near 1 Answer
Trouble with light switch 3 Answers
Change light color when entering trigger 1 Answer
Using shadows as Triggers? 1 Answer
Light switch trigger 3 Answers