Represents a Gradient used for animating colors.
Gradients allow animating or interpolating colors by having several "color keys" and "alpha keys". Color keys and alpha keys are separate, and each key has a time specified for it, ranging from 0.0 (0%) to 1.0 (100%). 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.
How the colors are interpolated between the keys is controlled by GradientMode.
Public Gradient variables used in scripts automatically display the gradient editor in the inspector window. GradientUsageAttribute allows specifying whether the gradient colors should be high dynamic range for editing.
using UnityEngine;
public class ExampleScript : MonoBehaviour { void Start() { var gradient = new Gradient();
// Blend color from red at 0% to blue at 100% var colors = new GradientColorKey[2]; colors[0] = new GradientColorKey(Color.red, 0.0f); colors[1] = new GradientColorKey(Color.blue, 1.0f);
// Blend alpha from opaque at 0% to transparent at 100% var alphas = new GradientAlphaKey[2]; alphas[0] = new GradientAlphaKey(1.0f, 0.0f); alphas[1] = new GradientAlphaKey(0.0f, 1.0f);
gradient.SetKeys(colors, alphas);
// What's the color at the relative time 0.25 (25%) ? Debug.Log(gradient.Evaluate(0.25f)); } }
alphaKeys | グラデーションで定義されたすべてのアルファキー |
colorKeys | グラデーションに定義されているすべてのカラーキー |
colorSpace | Indicates the color space that the gradient color keys are using. |
mode | Controls how the gradient colors are interpolated. |
Gradient | グラデーション( Gradient )オブジェクトを作成します |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.