Help setting UV coordinates for code-generated plane
Hello, I am having some problems creating mesh at run time. I can get the mesh created and texture applied, but for some reason I cannot get the UV coordinates properly calculated. What I am trying to do is create a top facing plane and only have 64x64 pixels of my 1024x1024 texture atlas applied to the whole plane. Another example is to be able to apply a different 64x64 patch of pixels in the same texture atlas to another plane if I were to generate two planes and wanted to use the same texture atlas. I hope you can understand my question and here is the code that I have already tried and been messing with for hours now. Thanks in advance everyone Mesh m = new Mesh { vertices = new Vector3[] { new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f) }, uv = GetUVs(0, 0), triangles = new int[] { 0, 1, 2, 0, 2, 3 } }; m.RecalculateNormals(); return m; } Vector2[] GetUVs(float getX, float getY) { float startX = (1f / 1024f) * getX; float startY = (1f / 1024f) * getY; float endX = (1f / 1024f) * (getX + 64f); float endY = (1f / 1024f) * (getY + 64f); return new Vector2[] { new Vector2(startX, startY), new Vector2(endX, startY), new Vector2(endX, endY), new Vector2(startX, endY) }; }