Linear interpolation between 2 numbers over time.

I’ve been looking at lerp and smoothdamp for interpolating between vector3’s - however I was wondering - how would I linearly interpolate between a single minimum and maximum numerical value?

so for example, given:

var min :float = 1;
var max :float = 20;
var power :float = 1;

How would I make “power” increment towards “max” and also have control over how long it would take?

You could use Mathf.Lerp inside Update or a coroutine, and set the duration time in seconds like below:

...
var t: float = 0; // set to zero to start interpolation 
var duration: float = 1; // duration in seconds

function Update(){

    power = Mathf.Lerp(min, max, t);
    if (t <= 1) t += Time.deltaTime/duration;
}

Each time you store 0 in t, the power value returns to min, then gradually ramp to max in duration seconds, and gets stuck at max until you store 0 in t again.