So I used the Brackeys mesh generation tutorial as reference since I didnt work with meshes in a while and I stumbled upon a bug that I dont understand why it is there. As you can see I increment my verts value by one after finishing the inner loop but for some reason my code still generates polygons when switching lines. Surely I am overseeing something here but after trying to trouble shoot it still happens and I think I need a second opinion on my code
//Generate mesh
void GenerateMesh()
{
triangles = new int[size * size * 6];
vertices = new Vector3[(size + 1) * (size + 1)];
for(int y = 0, i = 0; y < size; y++)
{
for(int x = 0; x < size; x++)
{
vertices[i] = new Vector3(x, noise[x, y] * 15, y);
i++;
}
}
int verts = 0;
int tris = 0;
for(int i = 0; i < size - 1; i++)
{
for(int j = 0; j < size - 1;j++)
{
triangles[tris + 0] = verts + 0;
triangles[tris + 1] = verts + size + 1;
triangles[tris + 2] = verts + 1;
triangles[tris + 3] = verts + 1;
triangles[tris + 4] = verts + size + 1;
triangles[tris + 5] = verts + size + 2;
tris += 6;
verts++;
}
verts++;
}
}
//Show mesh
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
}
Here you see the result (look from below):
Otherwise it works as intended