x


Particle renderer tint?

Hi. I am trying to change the tint color of a material that is being used by a particle render. I came up with this code, and although I am getting no errors, the tint color does not change. What is wrong? Thanks

var C  : Color[];

function Start(){
    GetComponent(ParticleRenderer).material.color=(C[Random.Range(0,10)]);

}
more ▼

asked Nov 22 '11 at 07:36 AM

Tofudude624 gravatar image

Tofudude624
165 28 69 94

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

1 answer: sort voted first

This is because the .color property of a material doesn't return tint color, it returns the MainColor, which is always called "_Color" in the source code of the built in shaders. :) Therefore, writing

GetComponent(ParticleRenderer).material.color=(C[Random.Range(0,10)]);

Is actually shorthand for:

GetComponent<ParticleRenderer>().material.SetColor("_Color", C[Random.Range(0,10)]);

If you want to set the tint color, you need to use SetColor and specify "_TintColor" instead:

GetComponent<ParticleRenderer>().material.SetColor("_TintColor", C[Random.Range(0,10)]);

Beware that this only works for shaders which have a property called _TintColor, obviously.

more ▼

answered Nov 22 '11 at 08:15 AM

CHPedersen gravatar image

CHPedersen
6k 13 22 61

Sorry about the <>-brackets in there. They snuck their way in from my editor when I wrote the example in C#. Just replace them with () in your JS code.

Nov 22 '11 at 08:17 AM CHPedersen
(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:

x813
x318
x265

asked: Nov 22 '11 at 07:36 AM

Seen: 1071 times

Last Updated: Nov 22 '11 at 08:19 AM