class in UnityEngine
/
Implemented in:UnityEngine.CoreModule
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseGradient used for animating colors.
See Also: GradientColorKey, GradientAlphaKey.
using UnityEngine;
public class ExampleScript : MonoBehaviour { Gradient gradient; GradientColorKey[] colorKey; GradientAlphaKey[] alphaKey;
void Start() { gradient = new Gradient();
// Populate the color keys at the relative time 0 and 1 (0 and 100%) colorKey = new GradientColorKey[2]; colorKey[0].color = Color.red; colorKey[0].time = 0.0f; colorKey[1].color = Color.blue; colorKey[1].time = 1.0f;
// Populate the alpha keys at relative time 0 and 1 (0 and 100%) alphaKey = new GradientAlphaKey[2]; alphaKey[0].alpha = 1.0f; alphaKey[0].time = 0.0f; alphaKey[1].alpha = 0.0f; alphaKey[1].time = 1.0f;
gradient.SetKeys(colorKey, alphaKey);
// What's the color at the relative time 0.25 (25 %) ? Debug.Log(gradient.Evaluate(0.25f)); } }
Note that the alpha and colors keys will be automatically sorted by time value and that it is ensured to always have a minimum of 2 color keys and 2 alpha keys.
alphaKeys | All alpha keys defined in the gradient. |
colorKeys | All color keys defined in the gradient. |
mode | Control how the gradient is evaluated. |
Gradient | Create a new Gradient object. |