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 this method when you need to blend two colors smoothly. The frac
parameter determines the weight of each color in the interpolation, where 0 results in color a
and 1 results in color b
. If clamped
is set to true
, the resulting color components will be clamped to the range [0, 1].
Color colorA = new Color(1.0f, 0.0f, 0.0f, 1.0f); // Red Color colorB = new Color(0.0f, 0.0f, 1.0f, 1.0f); // Blue float fraction = 0.5f; bool clamp = true; Color resultColor = Color.Lerp(ref colorA, ref colorB, fraction, clamp); // resultColor will be a blend of red and blue, resulting in purple if clamped.