Create mesh in code X divisions along one axis

Hi I have tried this and cannot seem to get this to work for whatever reason at the moment but basically I need to generate a “quad” with X amount of sections along it like:

If anyone would be able to knock together a small example that would be brilliant as my tired head seems to be getting me nowhere… many thanks’

for an example of how to get a simple quad you can take a look [here

untested code for splitting a quad, so most likely buggy, but hopefully with the right idea

EDIT: tested and added uvs and normals. Enjoy.

var numberOfSections : int;
var meshNormal = Vector3.up;
var meshCorners = [Vector3(-1,0,-1),Vector3(-1,0,1),Vector3(1,0,-1),Vector3(1,0,1)];
function Awake () {
	var myMesh : Mesh;
	myMesh = gameObject.GetComponent(MeshFilter).mesh;
	myMesh.Clear();
	var meshVertices = new Vector3[numberOfSections*2+2];
	var meshUVs = new Vector2[numberOfSections*2+2];
	var meshNormals = new Vector3[numberOfSections*2+2];
	var meshTriangles = new int[3*numberOfSections*2];
                for(i = 0; i < meshVertices.length; i+=2) {
                    meshVertices[i] = Vector3.Lerp(meshCorners[0], meshCorners[2], (i/2.0)/numberOfSections);
                    meshVertices[i+1] = Vector3.Lerp(meshCorners[1], meshCorners[3], (i/2.0)/numberOfSections);
					meshUVs[i] = Vector2((i/2.0)/numberOfSections,0);
					meshUVs[i+1] = Vector2((i/2.0)/numberOfSections,1);
					meshNormals[i] = meshNormal;
					meshNormals[i+1] = meshNormal;
                }
                var vertexIndex : int = 0;
                for(i = 0; i < numberOfSections; i++) {
                    meshTriangles[i*6] = i*2;
                    meshTriangles[i*6 + 1] = i*2 + 1;
                    meshTriangles[i*6 + 2] = i*2 + 2;

                    meshTriangles[i*6+3] = i*2 + 3;
                    meshTriangles[i*6+3 + 1] = i*2 + 2;
                    meshTriangles[i*6+3 + 2] =  i*2 + 1;              
                }
       myMesh.vertices = meshVertices;
       myMesh.triangles = meshTriangles;
	   myMesh.normals = meshNormals;
	   myMesh.uv = meshUVs;
}

](http://forum.unity3d.com/threads/78354-Back-to-the-basics-(scripting-a-mesh))

Thanks perfect!