LerpUnclamped
Linearly interpolates between colors a and b using the interpolation ratio t.
Read time 3 minutesLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
LerpUnclamped(Color, Color, float)
Linearly interpolates between colors and using the interpolation ratio .
abtpublic static Color LerpUnclamped(Color a, Color b, float t)
Parameters
Returns
Type | Description |
|---|---|
| Color | The color resulting from linear interpolation between |
Remarks
ttatbIf is less than 0, or greater than 1, the result will be linearly extrapolated from and . For example, will return a color given by .
tabColor.LerpUnclamped(new Color(0.0f, 0.0f, 0.0f), new Color(0.5f, 0.5f, 0.5f), 3.0f)new Color(1.5f, 1.5f, 1.5f)The script below will set the color of MeshRenderer to the result of unclamped interpolation using parameters specified in the inspector. To use the script, attach it to a GameObject with a MeshRenderer.
using UnityEngine;[RequireComponent(typeof(MeshRenderer))]public class ColorLerp : MonoBehaviour{ public Color colorA = Color.white; public Color colorB = Color.red; public float interpolationRatio = 0.5f; private Material material; private void Start() { material = GetComponent<Renderer>().material; } void Update() { material.color = Color.LerpUnclamped(colorA, colorB, interpolationRatio); }}
Additional Resources: Color.Lerp.
LerpUnclamped(Color, Color, float)
Linearly interpolates between colors and using the interpolation ratio .
abtpublic static Color LerpUnclamped(in Color a, in Color b, float t)
Parameters
Returns
Type | Description |
|---|---|
| Color | The color resulting from linear interpolation between |
Remarks
ttatbIf is less than 0, or greater than 1, the result will be linearly extrapolated from and . For example, will return a color given by .
tabColor.LerpUnclamped(new Color(0.0f, 0.0f, 0.0f), new Color(0.5f, 0.5f, 0.5f), 3.0f)new Color(1.5f, 1.5f, 1.5f)The script below will set the color of MeshRenderer to the result of unclamped interpolation using parameters specified in the inspector. To use the script, attach it to a GameObject with a MeshRenderer.
using UnityEngine;[RequireComponent(typeof(MeshRenderer))]public class ColorLerp : MonoBehaviour{ public Color colorA = Color.white; public Color colorB = Color.red; public float interpolationRatio = 0.5f; private Material material; private void Start() { material = GetComponent<Renderer>().material; } void Update() { material.color = Color.LerpUnclamped(colorA, colorB, interpolationRatio); }}
Additional Resources: Color.Lerp.