I have a problem for assign the material to object. In that object there are 2 materials.
I tried, renderer.material = material;
and renderer.materials[1] = material;
The first one modify the first material and second one does nothing. Pls help me to change the 2nd material…
Bunny83
3
The problem is that .materials is a property which returns a copy of the material array. All you can do is assign a new array to this property. To change the second material you would do something like:
var Sling : GameObject;
var Material1 : Material;
function OnMouseDown()
{
if(condition)
{
var mats = Sling.renderer.materials;
mats[1] = Material1;
Sling.renderer.materials = mats;
}
}
But be careful, this only works if there are two materials attached, otherwise you can’t just set another material. You would have to create a new, bigger array.
Hi there, try this:
var material0 : Material;
var material1 : Material;
-
function Update () {
if (some input) {
renderer.sharedMaterials[1] = material0;
}
if (other input) {
renderer.sharedMaterials[1] = material1;
}
}
Hope this help. 