The Color.Lerp
method performs a linear interpolation between two colors, a
and b
, based on a given fraction frac
. The interpolation can be clamped to ensure the resulting color components remain within the valid range of 0 to 1.
The Color.Lerp
method performs a linear interpolation between two colors, a
and b
, based on a given fraction frac
. The interpolation can be clamped to ensure the resulting color components remain within the valid range of 0 to 1.
Use the Color.Lerp
method when you need to blend two colors smoothly. This is particularly useful in animations, transitions, or any scenario where gradual color changes are required.
The method takes four parameters:
a
: The starting color, passed by reference.b
: The ending color, passed by reference.frac
: A float
value between 0 and 1 that determines the interpolation factor. A value of 0 returns color a
, and a value of 1 returns color b
.clamped
: A bool
indicating whether the resulting color should be clamped to the range [0, 1].// Example of using Color.Lerp Color startColor = Color.Red; Color endColor = Color.Blue; float fraction = 0.5f; // Midway between start and end bool clampResult = true; Color resultColor = Color.Lerp(ref startColor, ref endColor, fraction, clampResult); // resultColor will be a blend of red and blue, resulting in a purple color.