Apply the color gradient between these minimum and maximum speeds.
See Also: ParticleSystem.ColorBySpeedModule.color.
#pragma strict private var ps: ParticleSystem; public var hSliderValue: float = 1.0f; function Start() { ps = GetComponent.<ParticleSystem>(); var colorBySpeed: var = ps.colorBySpeed; colorBySpeed.enabled = true; var gradient: Gradient = new Gradient(); gradient.SetKeys([new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f)], [new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f)]); colorBySpeed.color = new ParticleSystem.MinMaxGradient(gradient); colorBySpeed.range = new Vector2(1.0f, 5.0f); } function Update() { var main: var = ps.main; main.startSpeed = hSliderValue; } function OnGUI() { hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 1.0f, 5.0f); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public float hSliderValue = 1.0f;
void Start() { ps = GetComponent<ParticleSystem>();
var colorBySpeed = ps.colorBySpeed; colorBySpeed.enabled = true;
Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) } );
colorBySpeed.color = new ParticleSystem.MinMaxGradient(gradient); colorBySpeed.range = new Vector2(1.0f, 5.0f); }
void Update() { var main = ps.main; main.startSpeed = hSliderValue; }
void OnGUI() { hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 1.0f, 5.0f); } }