So, right now, I’m attempting to try to get a flashlight to change from a spot light to a point light by pressing “e.” I have this code right now:
function Update() {
if (Input.GetKeyDown("e")) {
if (light.type == LightType.Spot)
light.type = LightType.Point;
light.intensity = 3;
light.range = 180;
else
light.type = LightType.Spot;
light.intensity = 5.5;
light.range = 281;
}
}
For some reason, the code doesn’t work, but it will work if I get rid of the light.intensity and light.range lines and leave just light.type. It tells me it has errors on line 11 and 19… But when I does what it says to fix it, the light then flashes to point and then goes back to spot immediately. Some help would be greatly appreciated.
I tried the code, and it changes the light from spot to point, but the intensity and range values still don't change. Edit: Turns out I had another code going... And now it's being REALLY weird. I have another code that toggles the flashlight on and off, and whenever I press the key to turn the flashlight, it just switches between point and spot instead of turning off. It seems that your code creates- Never mind, just got it to work. Thanks!
– TunerSymphonWell accept supernat's answer, since I was just trying to get you to realize what you were missing on your own. ;)
– iwaldrop