- Home /
Can't change particle material Tint Color with js
I have been trying to get this work, it might be some minor stupid mistake, but I losing my nerves. I want to change tint color of particle material and here is what I have been trying:
function Update () {
var alpha : float;
var lightOn : Color = Color.white;
var lightOff : Color = Color.black;
var duration : float = 1.0;
var lerp : float = Mathf.PingPong (Time.time, duration) / duration;
var color : Color = Color.Lerp (lightOn, lightOff, lerp);
//
//
GetComponent(ParticleRenderer).material.SetColor("_TintColor", color);
//This gives error: NullReferenceException: Object reference not set to an instance of an object
}
I have material assigned to mesh, not particle, could it be a problem? If so, how to solve it. I'm doing pinball table and trying to make flashing lights with simple planes just over table and use addive material to give lightning effect.
Comment
Answer by khellstr · May 24, 2012 at 06:57 PM
Now it works:
renderer.material.SetColor("_TintColor", color);
Don't know what I was thinking, but doing something else for a while surely helped.
Just tried this and like you show, it works if you call it from the built in renderer's material and not from the particle renderer's material.