how to assing the texture for particular material in a single mesh at runtime

how to assing the texture for particular material in a single mesh at runtime
normally i use renderer.material.mainTexture =texturetype; if the mesh has single material

so if the mesh has multiple material how to change the particular material in a mesh?at runtime

I am not sure wether this is a good solution but maybe you could create a public variable of type material assign the material in the inspector that you would like to change. And then change the texture on that through code. Like I said I’m not sure if this is the best solution out there but it was what I could come up with of the top of my head.

To access an individual material in a multiple material mesh you need to access the renderer’s materials array.

You can check out the docs for more info at Unity - Scripting API: Renderer.materials

Using this code x is the index number of the material you wish to modify. Take care to ensure x < renderer.materials.Length

renderer.materials[x].mainTexture = texturetype

@BPPHarv
thanks a lot got the solution