- Home /
Changing color of particles
The particles that I wish to change color are attached to a game object and have all the other necessary components such as the animator and renderer. Here is how I am coding it:
void ChangeColor() { if (GetComponent<ParticleAnimator>().colorAnimation[0] == new Color(255,255,255,10)) { Debug.Log("ChangeColor");
ParticleAnimator pAnimator = GetComponent<ParticleAnimator>();
Color[ ] modifedColors = pAnimator.colorAnimation;
for (int i = 0; i < modifedColors.Length; i++)
{
modifedColors[i] = Color.red;
}
}
else
{
Debug.Log("Already Changed");
}
}
Apparently, the condition comparing the first element of the colorAnimation of the ParticleAnimator component is not white, when i know that it is..What could be the problem?
I also tried GetComponent().colorAnimation[0].Equals(Color.white); and that did not help either.
Where are you assigning the modifiedColors back to the pAnimator?
right, i rushed through that, thanks DaveA, your suggestion was/is the answer.
Answer by Eric5h5 · Apr 27, 2011 at 05:52 AM
Are you sure it's white? Color.white is Color(1.0, 1.0, 1.0, 1.0) and you could be using Color(1.0, 1.0, 1.0, 0.0) or something.
@lampshade: colors in Unity are normalized in the 0.0 to 1.0 range. See the docs; the color values you're using in your code won't work at all. http://unity3d.com/support/documentation/ScriptReference/Color.html Assu$$anonymous$$g 8 bits per gun, 0.0 = 0, and 1.0 = 255. What you're using is Color(1.0, 1.0, 1.0, .0392) approximately, which is not Color.white.