- Home /
How to get a torch light that you can turn on/off
OK i have a fps character with a spotlight attached to the parent, At the moment i have been able to use a GUI as a button to turn on/off the light source.
But i want to be able to use a button on the keyboard to tell the light to turn on/off
How do i do this? ..
i also want it to start with a VAR so i can change the light source in the future..
Thankyou
Answer by Uriel_96 · Dec 30, 2010 at 03:01 AM
I usually try something like this but if you want to do this put an empty and parent it with the light and put this script in the empty:
var player : Transform;
var turnon = true;
var light : Transform;
if(Vector3.Distance(player.position,transform.position)<1.5){
if(Input.GetKeyDown("s")){
if(turn){
light.SetActiveRecursively(false);
turnon = false;
}else{
light.SetActiveRecursively(true);
turnon = true;
}
}
}
Note : Make sure the the empty is at the same position of the light.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
photocamera flash 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Uni2D Play() - Misunderstanding 3 Answers