- Home /
How to change the alpha element of particles/additive color?
How to change the alpha element of tree leafs color? (Particles/Additive) I try to make them fade in/fade out via lerp. using script, but i can not even find how to target the leaf color in the script. I try something like: renderer.material.color.a = Mathf.Lerp(1.0, 0.0, Time.time); But the material only has a Tint Color, and I don't know how to change that...
Answer by ScroodgeM · Jul 21, 2012 at 09:04 PM
Color c = renderer.material.GetColor("_TintColor"); c.a = Mathf.Lerp(1.0, 0.0, Time.time); renderer.material.SetColor("_TintColor", c);
be aware that after 1 second of playing you'll not see any changing
Thank you! This works perfect and is easy to change to suit different tasks. But it only works with materials with only one Element. can I target only one element of the material? Or do I have to have two separate objects, tree and it's leafs?
this works with one instance of $$anonymous$$aterial. so if more then one element uses this $$anonymous$$aterial, this will change color on all of them. if you want to change color only for one material, you should create new instance of $$anonymous$$aterial. example line:
renderer.material = new $$anonymous$$aterial(renderer.material);- this creates new material and sets it to object. now you can change material - this will not affect to other objects.
Thanks for the answer, but i meant this: I have an object with mesh renderer that has a material with "size" 2. First one is bumped diffuse, second is particles/additive. Is there a way to target the alpha channel of one of them, the second one in this instance? Because script automatically targets Element 0, wich doesn't have a tint color. It is probably a stupid question, but I can not find the answer in any lesson.
ok i understand
ins$$anonymous$$d of
renderer.materialuse
renderer.materials[X]where X is zero-based index of material, so for second material X=1
Your answer
Follow this Question
Related Questions
How to fade an image 1 Answer
Pull a color out of a Color.Lerp fade 1 Answer
Color.Lerp not lerping 2 Answers
Changing Alpha Thru Code Acts Weird 1 Answer