Hi! I have a texture atlas, which has several window textures. I wanted to have a single FBX plane which can display a rectangular part of the atlas, so as to show a single window. So I wrote this script :
var ulX : float;
var ulY : float;
var lrX : float;
var lrY : float;
function Start () {
var dmesh : Mesh = GetComponent(MeshFilter).mesh;
var dvertices : Vector3[] = dmesh.vertices;
var uvs : Vector2[] = new Vector2[dvertices.Length];
uvs[0] = Vector2(ulX,ulY);
uvs[1] = Vector2(ulX,lrY);
uvs[2] = Vector2(lrX,lrY);
uvs[3] = Vector2(lrX, ulY);
dmesh.uv = uvs;
}
This script worked fine, until I thought that since they all are using the same material, they can be combined to get better performance. I created an empty gameobject and made all the meshes its children, and used combinechildren. But the meshes continued to show the original atlas texture instead of the rectangular parts that they were supposed to show.
I noticed that the meshRenderer of the meshed were getting disabled on runtime. So while the game was still playing in the editor I enabled it, but then, as the camera moved, the texture flickered between the atlas and the part that they were supposed to show.
Thanks for reading.
-Vatsal