Fade Float Function

How can I make a float fade using a function? Using it like FadeSomeFloat(myFloat, 0.0, 10.0, 30); and that would fade the variable “myFloat” from 0 to 10 in 30 seconds.

Most would be thinking “why not lerp?” but A: lerping is annoying as hell. and B: I need to run this in another function so that my fades to rain rather than just jumping to it, this means that I’m gonna need to fade like 6 different variables.

As a technical answer to your question, you’ll need to use either a coroutine or a manually called method that moves the value over time, but as far as I know there is no out-of-the-box single-call method, only interpolation utilities you will have to continuously call.

Essentially, you’ll need to interpolate, however if you don’t like Lerp, there is also
and for other use cases, InverseLerp

you could always write your own static utility class to implement a coroutine on the fly from a single call, but at that point you are starting to create the basis of a tween engine, a utility specifically designed to help animate or adjust values between two states.

Now, for the less technical answer to your question, there are several of these tweening engines freely available on the asset store, as well as some fine paid ones, that are simple and powerful, and can make your life much easier for fading colors, positions, and floats with a one-time method call, and it sounds like this might be a good solution for you. I do have my favorites, but rather than plug them I encourage you to take a look and see which solution will suit you best


Use a float gradient which is what you are saying. Just google Unity float gradient and it will come up. It works in a similar way to what you put but is slightly longer.

I hope I helped!