- Home /
 
               Question by 
               AztrexVexation · Sep 21, 2020 at 10:07 PM · 
                materialrenderercombinemeshes  
              
 
              Scale Material after Combining Mesh Issue
I feel that I am likely missing something but after searching and trying a few solutions, no luck. What I am trying to achieve is each material having the same scale. Each object has a scale of 1,1,1, however they are still displaying stretched materials.
public class MeshCombiner : MonoBehaviour { public Texture m_Material; MeshRenderer rend;
 float scaleX = 2;
 float scaleY = 2;
 // Start is called before the first frame update
 void Awake()
 {
     rend = GetComponent<MeshRenderer>();
     Debug.Log(rend.material.GetTextureScale(1));
     rend.material.mainTextureScale = new Vector2(scaleX, scaleY);
     Debug.Log(rend.material.GetTextureScale(1));
     MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
     CombineInstance[] combine = new CombineInstance[meshFilters.Length];
     int i = 0;
     while (i < meshFilters.Length)
     {
         combine[i].mesh = meshFilters[i].sharedMesh;
         combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
         meshFilters[i].gameObject.SetActive(false);
         i++;
     }
     var meshFilter = transform.GetComponent<MeshFilter>();
     meshFilter.mesh = new Mesh();
     meshFilter.mesh = new Mesh();
     meshFilter.mesh.CombineMeshes(combine);
     GetComponent<MeshCollider>().sharedMesh = meshFilter.mesh;
     transform.gameObject.SetActive(true);
     transform.localScale = new Vector3(1, 1, 1);
     transform.rotation = Quaternion.identity;
     transform.position = Vector3.zero;
 }
}
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                