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
1 Answer
1
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.