So, when I was using my game project in a previous version of Unity, I set up textures for a normal Unity instanced 3d cube object from a texture atlas and then used a script to set the coordinate manually. The image below shows how it looks before and after updating to Unity 5.3. The left most is what it use to be, and the center is what it is at the moment. The right is the same one with a wireframe to show the details of the uvs.
As you can see, the texture on the side is somehow switched/ stretched now. I thought my UVs might have been out of order, but nothing changed from then to now as far as I’m aware. Did Unity 5 present something about uvs that I’m not aware of?
This is the code I used. The Left and Right code seems to be the culprits, though I believe this effect is also happening on the Bottom.
var mf = GetComponent(MeshFilter);
var mesh : Mesh;
if (mf != null)
mesh = mf.mesh;
if (mesh == null || mesh.uv.Length != 24) {
Debug.Log("Script needs to be attached to built-in cube");
return;
}
var uvs = mesh.uv;
// Front
uvs[0] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y);
uvs[1] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y);
uvs[2] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y + tUnit);
uvs[3] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y + tUnit);
// Top
uvs[8] = Vector2(tUnit * texturePosTop.x, tUnit * texturePosTop.y);
uvs[9] = Vector2(tUnit * texturePosTop.x + tUnit, tUnit * texturePosTop.y);
uvs[4] = Vector2(tUnit * texturePosTop.x, tUnit * texturePosTop.y + tUnit);
uvs[5] = Vector2(tUnit * texturePosTop.x + tUnit, tUnit * texturePosTop.y + tUnit);
// Back
uvs[6] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y);
uvs[7] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y);
uvs[10] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y + tUnit);
uvs[11] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y + tUnit);
// Bottom
uvs[12] = Vector2(tUnit * texturePosBot.x, tUnit * texturePosBot.y);
uvs[14] = Vector2(tUnit * texturePosBot.x + tUnit, tUnit * texturePosBot.y);
uvs[15] = Vector2(tUnit * texturePosBot.x, tUnit * texturePosBot.y + tUnit);
uvs[13] = Vector2(tUnit * texturePosBot.x + tUnit, tUnit * texturePosBot.y + tUnit);
// Left
uvs[16] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y);
uvs[18] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y);
uvs[19] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y + tUnit);
uvs[17] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y + tUnit);
// Right
uvs[20] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y);
uvs[22] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y);
uvs[23] = Vector2(tUnit * texturePosSides.x, tUnit * texturePosSides.y + tUnit);
uvs[21] = Vector2(tUnit * texturePosSides.x + tUnit, tUnit * texturePosSides.y + tUnit);
mesh.uv = uvs;