// Update is called once per frame
    void Update()
    {
        PlaneBuilder planeBuilder = new PlaneBuilder();

        planeBuilder.SetUpSubmeshes(subMeshSize);

        MeshFilter   meshFilter   = this.GetComponent <MeshFilter>();
        MeshRenderer meshrenderer = this.GetComponent <MeshRenderer>();
        MeshCollider meshcollider = this.GetComponent <MeshCollider>();

        //create points of plane
        Vector3[,] points = new Vector3[width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                points[x, y] = new Vector3(cellSize * x, cellSize * y);
            }
        }


        //create the quads

        int submesh = 0;

        for (int x = 0; x < width - 1; x++)
        {
            for (int y = 0; y < height - 1; y++)
            {
                Vector3 bRight = points[x, y];
                Vector3 bLeft  = points[x + 1, y];
                Vector3 tRight = points[x, y + 1];
                Vector3 tLeft  = points[x + 1, y + 1];

                //create 2 triangles that make up a quad
                planeBuilder.BuildMeshTriangle(bLeft, tRight, tLeft, submesh % subMeshSize);
                planeBuilder.BuildMeshTriangle(bLeft, bRight, tRight, submesh % subMeshSize);
            }

            submesh++;
        }

        meshFilter.mesh         = planeBuilder.CreateMesh();
        meshcollider.sharedMesh = meshFilter.mesh;
        planeBuilder.AddMaterials(meshrenderer);
    }