Apply different textures to multiple materials
I have a folder, called "Walls" in the Ressorce-folder, which contains multiple textures, calling "wallRoi[1-26]". Now I would like to apply those to my model in Unity via C# scripting. Explaning my code: The model has multiple segmentation of the whole wall, each of them has a tag ("Wall[1-26]"). The tag of the whole wall is "Wall". Now I'm trying to loop through the whole wall and apply to each segmenation of the wall a different texture from the folder. My Code doesn't work, any purposes? Thank you!
private UnityEngine.Object[] walltextures;
void mapTexturesOverWalls() {
walltextures = Resources.LoadAll ("Walls", typeof(Texture2D));
Texture2D[] wallTex = (Texture2D)walltextures [walltextures.Length];
GameObject walls = GameObject.FindGameObjectWithTag ("Wall");
Renderer[] renders = walls.GetComponentsInChildren<Renderer> ();
for (int i = 0; i < wallTex.Length; i++) {
foreach (Renderer r in renders) {
r.material.mainTexture = wallTex[i];
UnityEngine.Debug.Log (wallTex + "");
}
}
}
Your answer
Follow this Question
Related Questions
Networking Command class argument 2 Answers
,Why isnt my attack working? 0 Answers
Store Reference to a Serializable Class 0 Answers
How do i make it so when you are touched you are on the other teamlike in garrys mod hide and seek 1 Answer
Is it possible to use . Operator to access variables in classes in lists 1 Answer