Hello,
I’m working on a project where I am trying to programmatically adjust the UVs of meshes in my scene.
The meshes I’m working with represent the floors of the level and the changes to the UVs are to make sure the floor textures are consistently tiled regardless of the floor mesh size.
The changes to the UVs seem to work fine when running the game in the Unity Editor, but when I export a build to an Android device the changes don’t seem to take effect.
The code below is called on Awake()
foreach (var floor in area.FloorSurfaces) {
MeshFilter meshFilter = floor.GetComponent<MeshFilter> ();
List<Vector2> uvs = new List<Vector2> ();
foreach (var vertex in meshFilter.mesh.vertices) {
if (floor.transform.up.y > .5f) {
uvs.Add (new Vector2 (vertex.x * (floor.transform.lossyScale.x), vertex.z * (floor.transform.lossyScale.z)));
} else {
uvs.Add (new Vector2 (vertex.x * (floor.transform.lossyScale.x), vertex.y * (floor.transform.lossyScale.y)));
}
}
meshFilter.mesh.uv = uvs.ToArray();
}