Inspector で設定する場合
using UnityEngine;
public class Example : MonoBehaviour
{
public Gradient gradient;
}
![f:id:baba_s:20171227230833p:plain](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20171227/20171227230833.png)
![f:id:baba_s:20171227230756p:plain](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20171227/20171227230756.png)
スクリプトから設定する場合
using UnityEngine;
public class Example : MonoBehaviour
{
private void Awake()
{
var colorKeys = new []
{
new GradientColorKey( Color.red, 0 ),
new GradientColorKey( Color.blue, 1 ),
};
var alphaKeys = new []
{
new GradientAlphaKey( 1, 0 ),
new GradientAlphaKey( 0, 1 ),
};
var gradient = new Gradient();
gradient.SetKeys( colorKeys, alphaKeys );
}
}
スクリプトから参照する場合
using UnityEngine;
public class Example : MonoBehaviour
{
public Gradient gradient;
private void Awake()
{
Debug.Log( gradient.Evaluate( 0.5f ) );
}
}