x


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.

more ▼

asked Apr 27 '11 at 05:28 AM

lampshade gravatar image

lampshade
391 84 92 109

Where are you assigning the modifiedColors back to the pAnimator?

Apr 27 '11 at 05:48 AM DaveA

right, i rushed through that, thanks DaveA, your suggestion was/is the answer.

Apr 27 '11 at 09:41 AM lampshade
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 27 '11 at 05:52 AM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

@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 Assuming 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.

Apr 27 '11 at 07:21 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x638
x507

asked: Apr 27 '11 at 05:28 AM

Seen: 879 times

Last Updated: Apr 27 '11 at 05:58 AM