- Home /
Random Amongst 3 Colors in the Particle System
The new Shuriken particle system is pretty nice. One limitation I've run into however is that while it allows you to choose the color randomly between two colors or two gradients, I want every particle it spews to choose among 3 random colors from beginning to end, and not from the range between them but discretely one or the other - specifically, solid red, solid green or solid blue.
Would this require a drastic hack to re-write your own particle system, or is there a way to do this as-is?
Answer by ditzel · Nov 06, 2016 at 07:00 PM
Here is an approach completely without coding. First set the start color to gradient or random between to gradients. Than you define your gradient with the colors you want to instantiate.You can set hard gradient boundaries, to have a hard cut between colors. The colors are iterated one after another. If you want to have a fast iteration set the duration to 1.00.
Answer by Jesper Mortensen · Mar 08, 2013 at 07:47 AM
You can script this quite easily. Add a LateUpdate() function to your MonoBehaviour and do the following:
Use GetParticles (http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.GetParticles.html) to pull the particle array.
Then run through the array setting the ParticleSystem.Particle color member to your random discrete color and finally push the particle array again with SetParticles (http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.SetParticles.html).
Answer by Berenger · Feb 29, 2012 at 05:40 PM
I've never tried shuriken. But maybe you could get the particle array (particleEmitter.particles) and change manually the color for each of them ? How to choose the color randomly isn't the issue I suppose (just in case, Random.Range(0, 2) and a Color[]). It's getting more complicated if the emitter isn't a one shot though.