Hi, I need to figure out how I can set material to my prefabs that I create during runtime,
I tried several things, among those what u see below.
Surely there are more code, but this is what’s important in this situation:
private function buildTile(tileType:int, posX:float,posY:float) {
var x : Rigidbody;
x = Instantiate ( map, Vector3(posX, posY, 4),Quaternion.Euler( 90,0,0 ) );
[I]x.renderer.materials = red;[/I] <--- how to get this line to work :-)
thisMap.Push (x);
}
x.renderer.material.color = Color.red;
thanks KelsoMRK,
But I was looking to set a material, lets say i created a meaterial named “grass” that have applied a texture of grass, how could I change this line x.renderer.material.color = Color.red; to get the material from my list? cant seem to get it to work.
Set this var, and place the material in the Inspector:
var grass : Material;
Then you can change to that texture with this code:
renderer.material = grass;
[ you might want to set sharedmaterial instead of material - setting material creates a new instance of the material iirc ]