I’m trying to create a mesh in runtime but I don’t understand the Mesh class: How the vertices work for example.

I want to create a script that create’s a mesh, and I can give them parameter like generatemesh(heights, dimensionx, dimensiony) like a terrain. the heights should have different values only in one axis. so for example in every x=1 coord the height will be 5 and in every x=2 coord will be 10.

The ‘vertices’ array contains the positions of the vertices in the mesh, and the ‘triangles’ array indexes into the ‘vertices’ array, with each set of 3 consecutive indices describing a triangle.

You can arrange the vertices however you want, but for something like this you’d typically arrange the vertices by row and then by column or vice versa. Generating the triangle indices then just involves a loop and a little arithmetic.

For examples of how to create meshes via code, check out the examples in the documentation for the Mesh class (if you haven’t already), and the ‘procedural mesh’ examples on the Unity website.