I was hoping to upgrade my game WarPlan from Unity 2017 to 2019 but I hit a snag. I use a single png image and select the UV corners of the image to choose the unit on the map. In 2017 it works nicely In 2019 I get this slant.
I have searched the internet and I can’t find a solution after 75m. The strange part is that the background map uses the same UV shifting method and as you can see it works fine except it is for a hexagon mesh. The counters are a quad object. I’ve been slowly transforming the objects and code as I get better with Unity to more effective methods. You can buy WarPlan at Matrix Games or on Steam.
void ChangeUV(int tileTypeX, int tileTypeY) {
Renderer r = GetComponent<Renderer>();
r.material.mainTexture = images[1];
int textureWidth = r.material.mainTexture.width;
int textureHeight = r.material.mainTexture.height;
int tileColumns = textureWidth / MapManager.TileWidth;
int tileRows = textureHeight / MapManager.TileHeight;
float U0 = (float)(tileTypeX - 1) / tileColumns;
float V0 = (float)(tileRows - tileTypeY) / tileRows;
float U1 = (float)(tileTypeX) / tileColumns;
float V1 = (float)(tileRows - tileTypeY + 1) / tileRows;
float U2 = (float)(tileTypeX) / tileColumns;
float V2 = (float)(tileRows - tileTypeY) / tileRows;
float U3 = (float)(tileTypeX - 1) / tileColumns;
float V3 = (float)(tileRows - tileTypeY + 1) / tileRows;
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
Vector2[] uvs = new Vector2[vertices.Length];
uvs = mesh.uv;
uvs[1] = new Vector2(U0, V0);
uvs[0] = new Vector2(U1, V1);
uvs[2] = new Vector2(U2, V2);
uvs[3] = new Vector2(U3, V3);
mesh.uv = uvs;
}
