realtime texture change

hi,

i need to change the texture of a material.

i tried:
var newTexture : Texture;

renderer.material.mainTexture
renderer.material.SetTexture

but whats next? how do i apply a texture with the name XYZ to the material?
i just dont get it^^

thx for help

var newTexture : Texture;

renderer.material.mainTexture = newTexture;

–Eric

lol thx!
but i dont understand
lets say , the texture i want to assign is “CharDiffuse”
what do i write?

var newTexture : Texture = “CharDiffuse”;

renderer.material.mainTexture = newTexture;

???

the easiest way would be to drag the “CharDiffuse” texture onto the newTexture variable in the inspector

but i want to assign with script?

i think you misunderstood my previous post. you can save the new texture in a variable and then assign it via script when you need it. if, at the start of the game, you don’t know which texture you want to assign, i think you can use Resources.Load to find the right texture in the resources folder

thank you! that works