-
-
Save anchan828/b2b0a8266d4ea8ba4336 to your computer and use it in GitHub Desktop.
Gradient Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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