Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created December 1, 2012 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anchan828/b2b0a8266d4ea8ba4336 to your computer and use it in GitHub Desktop.
Save anchan828/b2b0a8266d4ea8ba4336 to your computer and use it in GitHub Desktop.
Gradient Example
using UnityEngine;
public class Example : MonoBehaviour
{
public Gradient g = new Gradient ();
void Start ()
{
GradientColorKey colorKey1 = new GradientColorKey ();
{
colorKey1.color = Color.red;
colorKey1.time = 0;
}
GradientColorKey colorKey2 = new GradientColorKey ();
{
colorKey2.color = Color.blue;
colorKey2.time = 1;
}
GradientAlphaKey alphaKey1 = new GradientAlphaKey ();
{
alphaKey1.alpha = 0;
alphaKey1.time = 0;
}
GradientAlphaKey alphaKey2 = new GradientAlphaKey ();
{
alphaKey2.alpha = 255;
alphaKey2.time = 1;
}
g.SetKeys (new GradientColorKey[]{colorKey1, colorKey2}, new GradientAlphaKey[] {alphaKey1, alphaKey2});
renderer.material.shader = Shader.Find ("Transparent/Diffuse");
}
void Update ()
{
renderer.material.color = g.Evaluate (Mathf.PingPong (Time.time, 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment