Accessing a texture

Does someone know how i should write my script to change one of the textures i have in a gameobject that have 5 differents textures?

the idea is that i only want that my avatar close the eyes. For that i have a texture, i only have to know how to change the texture of the face, that is the 6th texture on my game object. i can not use “main texture” in script… the main texture is the pant … :d

The Material class has a GetTexture command that lets you access a named texture.

Thank you, seems that will work beter :slight_smile: But something must be wrong in my script…

var eyesClose : Texture2D;
var Myu : GameObject;

function Start(){
	yield WaitForSeconds(15);
	var TexEyes = Myu.renderer.material.GetTexture("base.head");
	TexEyes = eyesClose;
}

I’m not sure if i have to write (“_base.head”) or simply (“base.head”) but i tried the 2 and no one works.

the console tell me: [Material doesn’t have a texture property ‘base.head’]

but you can see in the image above, that the name of te material is “base.head” and the name of the texture also, the same…

Can you help me?

240269--8600--$base_639.jpg

Ok well, i fix it, i find a good answer in another topic. So if it can help someone in future, here is the final script for it work:

var eyesClose : Texture2D; 

function Start(){
   yield WaitForSeconds(15); 
var Myu = GameObject.FindWithTag("avatar");
	Myu.renderer.materials[5].mainTexture = yeuxFermes;
}

So if i understand all, material[0] is the basic main material, and if you have 6 materials in your object, you want to change the 4rth material, you will call it material[3] :slight_smile:

And works perfectly :wink: