- Home /
How to change one of the materials in javascript?
I'm having 3 materials in mesh.I want to change 3rd material through javascript. When i use rendere.material it changes 1st one. How to chage third material?
Answer by AeonIxion · Oct 25, 2012 at 11:03 AM
use renderer.materials[2]
EDIT:
from the reference: "Note that like all arrays returned by Unity, this returns a copy of materials array"
This means that if you change something in the array you received, it won't change the actual array. Try this:
Material[] mats = renderer.materials;
mats[1] = newmaterial;
renderer.materials = mats;
renderer.materials[2] gets value it doesn't set to new value
I got this line in unity docs in reference of renderer.materials
Note that like all arrays returned by Unity, this returns a copy of materials array. If you want to change some materials in it, get the value, change an entry and set materials back
I think this tells how to change the numbered material. Can anybody explain it?
edited my answer
lol, was editing my answer with it while you asked:)
Your answer
