- Home /
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)]);
}
Answer by CHPedersen · Nov 22, 2011 at 08:15 AM
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.
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613051852im_/https://answers.unity.com/themes/thub/images/avi.jpg)