I’ve been adapting some example code from a site here on how to create a square grid of meshes:
Unfortunately, it creates squares so that the texture draws from the upper left of the square to the lower right, rather than unity style coordinate system of drawing lower left to upper right.
I can change my meshes to they are just one unit up, but I’d rather avoid that if I can. So I tried editing this from his sample code:
newVertices.Add( new Vector3 (x , y , 0 ));
newVertices.Add( new Vector3 (x + gridSquareSize , y , 0 ));
newVertices.Add( new Vector3 (x + gridSquareSize , y - gridSquareSize , 0 ));
newVertices.Add( new Vector3 (x , y - gridSquareSize , 0 ));
newTriangles.Add(squareCount*4);
newTriangles.Add((squareCount*4)+1);
newTriangles.Add((squareCount*4)+3);
newTriangles.Add((squareCount*4)+1);
newTriangles.Add((squareCount*4)+2);
newTriangles.Add((squareCount*4)+3);
newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y + tUnit));
newUV.Add(new Vector2 (tUnit*texture.x+tUnit, tUnit*texture.y+tUnit));
newUV.Add(new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y));
newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y));
to
newVertices.Add( new Vector3 (x , y , 0 ));
newVertices.Add( new Vector3 (x + gridSquareSize , y , 0 ));
newVertices.Add( new Vector3 (x + gridSquareSize , y + gridSquareSize , 0 ));
newVertices.Add( new Vector3 (x , y + gridSquareSize , 0 ));
newTriangles.Add(squareCount*4);
newTriangles.Add((squareCount*4)+1);
newTriangles.Add((squareCount*4)+3);
newTriangles.Add((squareCount*4)+1);
newTriangles.Add((squareCount*4)+2);
newTriangles.Add((squareCount*4)+3);
newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y));
newUV.Add(new Vector2 (tUnit*texture.x+tUnit, tUnit*texture.y));
newUV.Add(new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y + tUnit));
newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y + tUnit));
For each square. But it doesn’t seem to work, it just shows a blank screen. I know I should be mapping vertices to texture coordinates, but I cannot figure out how it works. Or maybe I am getting it right, but I don’t understand triangles correctly…