Inspector で設定する場合
using UnityEngine;
public class Example : MonoBehaviour
{
public Gradient gradient;
}
スクリプトから設定する場合
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 ) );
}
}