x


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.

more ▼

asked May 24 '12 at 12:01 PM

khellstr gravatar image

khellstr
45 6 10 12

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

1 answer: sort voted first

Now it works:

    renderer.material.SetColor("_TintColor", color);

Don't know what I was thinking, but doing something else for a while surely helped.

more ▼

answered May 24 '12 at 06:57 PM

khellstr gravatar image

khellstr
45 6 10 12

(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:

x5087
x817
x255
x19
x4

asked: May 24 '12 at 12:01 PM

Seen: 1050 times

Last Updated: May 24 '12 at 10:31 PM