Getting the vertices of a triangle of a mesh

So I grab an array of the verts and tris of a mesh:

int[] meshTriangles = colliders[coll].GetComponent<MeshFilter>().sharedMesh.triangles;
Vector3[] meshVertices = colliders[coll].GetComponent<MeshFilter>().sharedMesh.vertices;

But I can’t seem to grab any of the vertices of a triangle doing this: (getting the x-coord)

meshVertices[meshTriangles[0][0]].x;

The part “meshTriangles[0][0]” is underlined in red. “Cannot apply indexing with to an expression of type int”

That’s because Mesh.triangles is a one-dimensional array, so is not valid.

Mesh.triangles is an array of vertex indices. You need to read 3 at the time to make up one triangle. The simplest example would be a quad. Let’s say you have a square, with these corners (doing it in 2D for simplicity)

index -> coordinates
   0  ->  0, 10
   1  -> 10, 10
   2  -> 10,  0
   3  ->  0,  0

You could define two triangles, the first one using vertices [0, 1, 2] and the second one with vertices [0, 2, 3]

With that in mind, Mesh.vertices would be an array of 4 vertices (the ones listed above) and Mesh.triangles an array of 6 indices: [0, 1, 2, 0, 2, 3], each group of 3 defining one triangle