How do I texture this voxel cube?

I am still trying to understand voxel programming and just starting to understand it. Right now I have it so it generates a cube. I decided I would try to get it to generate a texture on the cube but looking at other peoples code I didn’t understand it enough to put it in the script. So if you could put it in and explain a little I would like that:).
This is the texture I am using for now

alt text

this is the script so far

var newVertices : Vector3[];
var newUV : Vector2[];
var newTriangles : int[];
var material : Texture2D;
 
function Start () {
var mesh : Mesh = new Mesh ();
GetComponent(MeshFilter).mesh = mesh;
mesh.Clear();

var p1 = Vector3(0,0,0);
var p2 = Vector3(1,0,0);
var p3 = Vector3(0,1,0);
var p4 = Vector3(0,0,1);
var p5 = Vector3(1,0,1);
var p6 = Vector3(1,1,0);
var p7 = Vector3(0,1,1);
var p8 = Vector3(1,1,1);
 
newVertices = new Array (p1,p2,p3,p4,p5,p6,p7,p8);
 
newTriangles = [0,2,1, 1,2,5, 3,0,1, 1,4,3, 0,3,2, 2,3,6, 1,5,4, 5,7,4, 6,3,4, 6,4,7, 6,5,2, 7,5,6];
 
mesh.vertices = newVertices;
mesh.triangles = newTriangles;
mesh.uv = newUV;



mesh.RecalculateNormals();  
mesh.RecalculateBounds();  
mesh.Optimize(); 

}

what this dose

alt text

Take a look at this tutorial, it includes code for UVs:

You just imagine each face of the cube as lying on a 2-dimensional plane, and then you just give each vertice you defined a xy coordinate on this plane from 0 to 1. I would suggest using lists for vertices, triangles and uvs so you can just add new elements on the fly instead of having to deicde the array sizes beforehand.

If you want to learn more, take a look at this thread:

http://forum.unity3d.com/threads/after-playing-minecraft.63149/