I'm creating hexagonal prisms from code and am having a difficult time understanding how UV mapping works, as the texture I apply to the hexagonal face comes out skewed:
Forgetting the sides for now, here is how I'm creating the hexagonal face:
meshData.vertices.Add(new Vector3(x, y + 0.5f, z + 0.5f)); // N
meshData.vertices.Add(new Vector3(x + 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z + 0.5f / 2)); // NE
meshData.vertices.Add(new Vector3(x + 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z - 0.5f / 2)); // SE
meshData.vertices.Add(new Vector3(x, y + 0.5f, z - 0.5f)); // S
meshData.vertices.Add(new Vector3(x - 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z - 0.5f / 2)); // SW
meshData.vertices.Add(new Vector3(x - 0.5f * (Mathf.Sqrt(3) / 2), y + 0.5f, z + 0.5f / 2)); // NW
This creates a regular hexagon. My texture is also a regular hexagon. So why does it get textured at an angle?
Here is my UV code:
meshData.uv.Add(new Vector2(0.5f, 1));
meshData.uv.Add(new Vector2(1, 0.75f));
meshData.uv.Add(new Vector2(1, 0.25f));
meshData.uv.Add(new Vector2(0.5f, 0));
meshData.uv.Add(new Vector2(0, 0.25f));
meshData.uv.Add(new Vector2(0, 0.75f));