Hello. I know how you can change the color of particles from a script, how can I make it so that every time the effect is instantiated, the colors are different? Thanks.
You can attach the following script to a Particle System game object:
C#
ParticleAnimator particleAni;
void Start()
{
particleAni = GetComponent<ParticleAnimator>();
Color[] aniColors = particleAni.colorAnimation;
for (int i = 0; i < aniColors.Length; i++)
{
aniColors[i].r = Random.Range(0.0f, 1.0f);
aniColors[i].g = Random.Range(0.0f, 1.0f);
aniColors[i].b = Random.Range(0.0f, 1.0f);
aniColors[i].a = Random.Range(0.0f, 1.0f);
}
particleAni.colorAnimation = aniColors;
}
Translated to JavaScript
private var particleAni: ParticleAnimator;
function Start()
{
particleAni = GetComponent("ParticleAnimator");
var aniColors: Color[] = particleAni.colorAnimation;
for (int i = 0; i < aniColors.Length; i++)
{
aniColors[i].r = Random.Range(0.0f, 1.0f);
aniColors[i].g = Random.Range(0.0f, 1.0f);
aniColors[i].b = Random.Range(0.0f, 1.0f);
aniColors[i].a = Random.Range(0.0f, 1.0f);
}
particleAni.colorAnimation = aniColors;
}