creating a mesh procedurally

hi guys i want to generate a simple mesh at runtime and then use it for my object's mesh renderer but i can not see anything on the screen. i think my problem is with setting triangles. is there anyone that he knows how should i set triangles and what are the different approaches for setting triangles vertecies?

this is my code

using UnityEngine;
using System.Collections;
public class album : MonoBehaviour
{
    public Texture2D tex;
    Mesh m;
    IEnumerator Start()
    {
        yield return new WaitForSeconds(1f);
        m = new Mesh();
        m.vertices = new Vector3[5];
        m.uv = new Vector2[5];
        m.normals = new Vector3[5];
        m.normals[0] = new Vector3(0,0,-1); ;
        m.normals[1] = new Vector3(0, 0, -1);
        m.vertices[0].x = 0;
        m.vertices[0].y = 0;
        m.vertices[0].z = 0;
        m.uv[0] = new Vector2 (0,0);
        m.vertices[1].x = 1;
        m.vertices[1].y = 0;
        m.vertices[1].z = 0;
        m.uv[1] = new Vector2(1, 0);
        m.vertices[2].x = 0;
        m.vertices[2].y = -1;
        m.vertices[2].z = 0;
        m.uv[2] = new Vector2(0, 1);
        m.vertices[3].x = 1;
        m.vertices[3].y = -1;
        m.vertices[3].z = 0;
        m.uv[3] = new Vector2(1, 1);
        m.vertices[4].x = 0;
        m.vertices[4].y = 0;
        m.vertices[4].z = 0.3f;
        m.uv[4] = new Vector2(1, 1);
        m.triangles = new int[9];
        m.triangles[0] = 0;
        m.triangles[1] = 1;
        m.triangles[2] = 2;
        m.triangles[3] = 2;
        m.triangles[4] = 3;
        m.triangles[5] = 1;
        m.triangles[6] = 1;
        m.triangles[7] = 0;
        m.triangles[8] = 4;
        m.RecalculateBounds();
        MeshFilter mf = (MeshFilter)transform.GetComponent(typeof(MeshFilter));
        mf.mesh = m;
        renderer.material = new Material(Shader.Find(" Diffuse"));
        mf.renderer.material.mainTexture = tex;
    }
}

This tutorial from the UniKnowledge contest covers creating meshes via scripting, including how to correctly set the triangles (see page 9 of the pdf in Tutorial.zip).

Hey guys,

Sorry for the late response. I've been swamped and am in the process of transitioning hosting, so my server is down. You can temporarily access the tutorial here: http://dl.dropbox.com/u/680550/MeshTutorial.zip

It's an archive that contains the tutorial PDF and the required files. Sorry for the inconvenience!

Best wishes,

-Lincoln Green

I believe you need to fill in your array values first and then finish by assigning mesh.uvs, mesh.uvs, mesh.vertices, mesh.triangles, all at once as in the Mesh documentation examples - http://unity3d.com/support/documentation/ScriptReference/Mesh.html

But can you see the new mesh gets applied in the inspector to your transform?

I never really created meshes at runtime but did you try using "m.RecalculateNormals();" instead?