Dynamically cahnging a texture on a material

can someone tell me how to change a texture that is attached to a material ( with code )?

thanks,
chris

Hey Chris

I’m not much of a coder but heres what I’ve been doing -

var mainShader : Material;
private var textureWorld1 : Texture;

function LoadTexture(){
textureWorld1 = Resources.Load("Textures/textUV", Texture2D);
if(textureWorld1){ 
        mainShader.SetTexture("_MainTex", textureWorld1);
}
}

Just assign the material you want to change to the ‘mainShader’ var and have your textures in a resources folder.

This is using the Resources.Load There is documentation here -