How to smoothly increase light intensity?

I have a fire that ignites, so suddenly turning a light on looks a bit weird.
instead I want to slowly increase the light intensity but I am not sure how to do this.

This is what I have so far but it instantly goes to the max setting:

	fireLight.light.intensity = 0;
	fireLight.light.enabled=true;
	audio.Play();
	while(fireLight.light.intensity < 4)
		{
		print(fireLight.light.intensity);
		fireLight.light.intensity = Mathf.Lerp(0,4,Time.time); 
		}

So what am I doing wrong?

You should use instead the deltaTime to do this. You could add the deltaTime or use it as a multiplier factor for some other variable. If you use a while loop it will be executed all in one update function, it won’t be distributed over the frames, that’s why the light goes on suddenly. In other words:

var lightStep : float = 10;

function Update() {
        fireLight.light.intensity += lightStep * Time.deltaTime;
}

and then maybe stopping increasing when a certain value has been reached :wink:

1 Like

Thanks,

I wanted to avoid the update function with the while loop, but guess I have no choice,
Did not know the animation editor could be used for things like this, I have a look at that too.