Author: Eric Haines (Eric5h5)
In Unity 2.6, several functions, namely Vector3.Lerp, Vector4.Lerp, and Color.Lerp, were sped up a fair amount compared to the previous versions of Unity. Unfortunately, they—along with other Lerp functions—still aren't as fast as they could be. Perhaps this will be changed in the future, but as of Unity 3.5, replacing these with user-made functions results in a noticeable speed increase.
"Noticeable" is relative, though...in general usage, it's unlikely to be worth the bother of using this script. On the other hand, if you're running routines that operate on large datasets and/or typically loop hundreds of thousands of times or more, then it can be worthwhile. Basically, any time you really want to squeeze more speed out of your code.
This also adds two new functions: Vector2Lerp and SuperLerp. (Vector2.Lerp was added in Unity 3.0, but this implementation is a little faster.)
The directly replaced functions are: MathS.Lerp, MathS.InverseLerp, and MathS.SmoothStep. In addition, you can replace Color.Lerp with MathS.ColorLerp. Vector3.Lerp can be replaced with MathS.Vector3Lerp. Vector4.Lerp can be replaced with MathS.Vector4Lerp.
Vector2.Lerp doesn't exist prior to Unity 3.0, but is included here in case you need it:
static function Vector2Lerp (from : float, to : float, value : float) : Vector2
Linearly interpolates between two vectors: from towards to by amount value, where value is clamped between [0...1].
Another new function is MathS.SuperLerp. This takes the form:
static function SuperLerp (from : float, to : float, from2 : float, to2 : float, value : float) : float
It's the equivalent of doing this:
Mathf.Lerp (from, to, Mathf.InverseLerp (from2, to2, value))
In other words, it's like Lerp, except the control parameter is an arbitrary range instead of only 0 through 1. The arbitrary range itself is controlled by value, which is clamped between from2 and to2. The reason for using SuperLerp is that it's faster and a little simpler than using the Lerp/InverseLerp combo. An example of usage, which would be useful for underwater effects: