x


Random colors for particles?

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.

more ▼

asked Nov 30 '10 at 02:26 AM

Tyler 2 gravatar image

Tyler 2
1.1k 212 247 264

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first

Sadly due to snow and a lack of a pc nearby, I can't test the following. You could store the particle number in script and then when more particles exist try something like:


particle.color = new Color32(Random.Range(0, 255), Random.Range(0, 255), Random.Range(0, 255), 255);

See http://unity3d.com/support/documentation/ScriptReference/Particle.html for more info. See http://unity3d.com/support/documentation/ScriptReference/ParticleEmitter-particles.html to learn how to get and set particles from the emitter.

I hope this helps :)

more ▼

answered Nov 30 '10 at 08:39 AM

Mendicant gravatar image

Mendicant
51 1 1 3

Didn't work for me. when i put in with a GetKeyUp code it only turns white HELP

Nov 22 '11 at 04:57 PM DzjengisKhan

Colors are not 0-255 unless you use the Color32 class.

Nov 22 '11 at 04:59 PM Jessy

@DzjengisKhan: Don't ask questions as an ANSWER to this question. Answers should answer the question. Use "add new comment" if you want to clarify something.

Beside that, yes you're right, It will most the time return a white color because the Color struct uses values between 0.0 and 1.0

To use byte color values you can use the Color32 struct which converts automatically into a Color struct.

So either use:

// C#
particle.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1.0f);
// UnityScript
particle.color = Color(Random.Range(0.0, 1.0), Random.Range(0.0, 1.0), Random.Range(0.0, 1.0), 1.0);

or

// C#
particle.color = new Color32(Random.Range(0, 255), Random.Range(0, 255), Random.Range(0, 255), 1);

// UnityScript
particle.color = Color32(Random.Range(0, 255), Random.Range(0, 255), Random.Range(0, 255), 255);
Nov 22 '11 at 05:06 PM Bunny83

I've fixed the answer ;)

Nov 22 '11 at 05:07 PM Bunny83
(comments are locked)
10|3000 characters needed characters left
Be the first one to answer this question
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:

x659
x598
x526

asked: Nov 30 '10 at 02:26 AM

Seen: 2351 times

Last Updated: Nov 22 '11 at 05:07 PM