Advertisement
polyfied

Particle Playground - Change Lifetime Color

Nov 21st, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. /* To change the lifetime color’s gradient through script you can assign a new gradient onto the lifetimeColor variable as such: */
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5. using ParticlePlayground;
  6.  
  7. public class ChangeLifetimeGradient : MonoBehaviour {
  8.  
  9.     public PlaygroundParticlesC particles;
  10.     public Gradient newGradient;
  11.  
  12.     void Start () {
  13.         particles.lifetimeColor = newGradient;
  14.     }
  15. }
  16.  
  17. /* Would you like to only change a particular part of the gradient you can reach into the gradient’s keys and set a new color, here’s how you can change the end color of a gradient: */
  18.  
  19. using UnityEngine;
  20. using System.Collections;
  21. using ParticlePlayground;
  22.  
  23. public class ChangeLifetimeGradient : MonoBehaviour {
  24.  
  25.     public PlaygroundParticlesC particles;
  26.     public Color newEndColor;
  27.  
  28.     void Start () {
  29.  
  30.         // Get the color- and alpha keys of the current lifetime gradient
  31.         GradientColorKey[] newLifetimeColorKeys = (GradientColorKey[])particles.lifetimeColor.colorKeys.Clone();
  32.         GradientAlphaKey[] newLifetimeAlphaKeys = (GradientAlphaKey[])particles.lifetimeColor.alphaKeys.Clone();
  33.  
  34.         // Apply the new end color
  35.         newLifetimeColorKeys[newLifetimeColorKeys.Length-1].color = newEndColor;
  36.  
  37.         // Set the color- and alpha keys back into the lifetime gradient
  38.         particles.lifetimeColor.SetKeys(newLifetimeColorKeys, newLifetimeAlphaKeys);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement