Hi,
I got a lightpoint with the following script attached to it. When I press the Z key, the light will turn on/off. But how do I get it to fade on/off as well? I can’t seem to get this to work.
Script, which is attached to the light.
private var lanternOn = false;
var fadeFrom = 0.0;
var fadeTo = 4.0;
var fadeRate = 10;
light.intensity = 0;
function Update(){
if(Input.GetKeyDown("z")){
if(lanternOn){
//light.intensity = 0;
fadeFrom = 4.0;
fadeTo = 0.0;
light.intensity = Mathf.Lerp(fadeFrom,fadeTo,fadeRate);
lanternOn = false;
}else{
//light.intensity = 4;
fadeFrom = 0.0;
fadeTo = 4.0;
light.intensity = Mathf.Lerp(fadeFrom,fadeTo,fadeRate);
lanternOn = true;
}
}
}