Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Unity3D - Apply different textures to multiple materials

Unity3D - Apply different textures to multiple materials

View previous topic View next topic Go down  Message [Page 1 of 1]

vickal93


Member [Lv. 0]
Member [Lv. 0]
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!

Code:

    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 + "");
             }
          }
       }

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum