I’m trying to delete quads in unity. The code here creates a procedural grid. Setting the gridSizeX to 5 and gridSizeY to 3, creates a 6 by 4 grid. I want to delete the first row of quads when I click the left mouse button (later will implement a trigger to delete). I have created a DeleteTriangle() method but it doesn’t work properly. I would like to delete all the quads in the first row when I first click the left mouse button. When I click again, it should remove the next row and so on. Here is the code I have:

```
(RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)))
public class Grid : MonoBehaviour
{
Mesh mesh;
Vector3() vertices;
int() triangles;
public float cellSize = 1;
public int gridSizeX, gridSizeY;
void Awake()
{
mesh = GetComponent<MeshFilter>().mesh;
}
void Start()
{
MakeGrid();
UpdateMesh();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
DeleteTriangle(0);
}
}
void MakeGrid()
{
//set array sizes
vertices = new Vector3(gridSizeX * gridSizeY * 4);
triangles = new int(gridSizeX * gridSizeY * 6);
//set tracker integers
int v = 0;
int t = 0;
for (int x = 0; x < gridSizeX; x++)
{
for (int y = 0; y < gridSizeY; y++)
{
Vector3 cellOffset = new Vector3(x * cellSize, 0, y * cellSize);
//populate the vertices and triangles arrays
vertices(v) = new Vector3(-cellSize, 0, -cellSize) + cellOffset ;
vertices(v + 1) = new Vector3(-cellSize, 0, cellSize) + cellOffset ;
vertices(v + 2) = new Vector3(cellSize, 0, -cellSize) + cellOffset ;
vertices(v + 3) = new Vector3(cellSize, 0, cellSize) + cellOffset ;
triangles(t) = v;
triangles(t + 1) = triangles(t + 4) = v + 1;
triangles(t + 2) = triangles(t + 3) = v + 2;
triangles(t + 5) = v + 3;
v += 4;
t += 6;
}
}
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
}
private void DeleteTriangle(int id)
{
Mesh currentMesh = mesh;
var triangles = currentMesh.triangles.ToList();
triangles.RemoveAt(id );
triangles.RemoveAt(id );
triangles.RemoveAt(id );
currentMesh.Clear();
currentMesh.vertices = vertices.ToArray();
currentMesh.triangles = triangles.ToArray();
currentMesh.RecalculateNormals();
}
}
```