Problem with assigning vertices to a mesh

I’m just learning about meshes, and I have problems understanding how they work. As a test, I made this code :

using UnityEngine;
using System.Collections;

public class MeshScript : MonoBehaviour 
{    
    void Start() 
    {
        Mesh mesh = GetComponent<MeshFilter>().mesh;

        int i = 0;
        while (i < mesh.vertices.Length) 
        	{
                 mesh.vertices[i] = new Vector3(0,0,0);
                 i++;
        	}
    }
}

And put this code in a cube . What I expected it to do was set all the vertices of the cube mesh to (0,0,0), making the cube disappear. However, the cube still appears, unchanged, in my game. What am I doing wrong ?

Thank you
Tabc3dd

You can’t write individually vertices from the C# managed environment. You have to create a new array and assign it to the ‘vertices’ property of the mesh object like this :

Vector3 [] newVertices = new Vector3 [length] ;
for ( int i = 0 ; i < length ; ++i )
{
      newVertices[i] = new Vector3(0,0,0) ;
}
mesh.vertices = newVertices ;

The same is true for faces, normals, uvs, etc…

Thank you, that worked