Smooth change of light range

Hello!
How to make , when you press the J key, smoothly changed range

if (Input.GetKeyDown(KeyCode.J))
{
lightT.range = Mathf.Lerp(startRange, endRange, speedRange);
}

in my case, everything happens instantly, you can example?
Thanks

Here’s all the documentation you need to do it.

I wouldn’t touch coroutines for this because it’s just unnecessary complexity, especially if you plan to possibly interrupt or reverse the transition.

Instead:

Fading, simple and easy:

Smoothing movement between any two particular values:

You have currentQuantity and desiredQuantity.

  • only set desiredQuantity
  • the code always moves currentQuantity towards desiredQuantity
  • read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: SmoothMovement.cs · GitHub

1 Like