- Home /
Changing Color of Particles in Javascript
Hi,
I've created the option of color customisation using some GUI Sliders and the renderer.material.color
command thingy. However, that only works with materials (obviously). To get it to change the color of a particle system, I tried what the Unity Script Reference said to do:
function Start ()
{
var modifiedColors : Color[] = particleAnimator.colorAnimation;
modifiedColors[2] = ColorCustGlow.glowColor; //My color is a static variable in another script
particleAnimator.colorAnimation = modifiedColors;
}
But that didn't work - Unity had no idea what particleAnimator
was. I also tried to put GetComponent
in there, but that didn't help at all. Is there something obvious I'm missing??
PS. I also tried it without my reference to another script, but instead Color.yellow
, and it still didn't work...
Answer by Eric5h5 · Aug 19, 2010 at 06:11 AM
Not every component has a shortcut; you'd have to use GetComponent(ParticleAnimator). (So the script example in the docs isn't correct.)
Thanks heaps mate, the script works fine now. I had tried GetComponent(particleAnimator) earlier, but not with a capitalised 'P', so the asme error came up. Strange thing is, only about half the particles are the new colour, but that's probably nothing a little fiddling won't fix. Thanks again!
Your answer
Follow this Question
Related Questions
How to turn on/off the animate color section in a Particle System through a program. 3 Answers
Random.Range doesn't work 1 Answer
Change material color at runtime!! 5 Answers
attract particles 3 Answers