Easy demand but unsolvable?? Set a permanent size (width and height) of a Texture even on different sized objects (c#)
Hey,
I´m writing an MenuItem (edit mode) which puts new materials on objects.
The problem: I just don´t know how to set the width and height of the textures so that it is always the same even on different sized objects.
An example: I got two wall-objects of different sizes. Both have the same brick-material on it. I now link a brick-texture to the material. Unfortunately it is adjusting the size of the texture to the size of the wall so that I got different sized bricks on both walls.
I am able to tile (mainTextureScale) or set an offset (mainTextureOffset) but those variables are also dependant to the size of the walls...
I would like to tell Unity that this texture has for example a width of 1 (Unity-units) and a height of 2 (Unity-units) independent from the objects they are linked to.
My c# Code:
 public class Editor_ChangeMaterial_08_Link: EditorWindow 
 {    
     [MenuItem("Add-on/Change material)")] 
 
     public static void Change()
     {
         GameObject SelectedObject = Selection.activeGameObject;    
         Material[] materials = SelectedObject.GetComponent<Renderer> ().sharedMaterials;
         .
         .
         .
 
         Texture2D NewMapTex = Resources.Load ("Texture/Texture_001") as Texture2D;  
         SelectedObject.GetComponent<Renderer> ().sharedMaterials[1].SetTexture("_MainTex", NewMapTex);
         
 
         // **Here I would like to set the size of the loaded texture**
 
 
     }
 }
 
               Is that even possible? Thank in advance for help!
Your answer