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)]);
}
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.