Applying separate materials to each side of a procedurally generated mesh

Hey everyone,

I’ve recently learnt how to procedurally generate a cube mesh, and I’m having a bit of trouble assigning materials to the different sides of it.

The reason for generating the mesh instead of using unity’s cube is for 2 reasons:

  1. I can’t for the life of myself get more then one texture to appear on a Cube properly

and

  1. The bottom of the cube will never be seen, so I’m generating the cube without a bottom (Figure I’m saving something from doing that)

Everything has being going great, I’ve done some small tutorials on OpenGL before so I knew how to assign verts and render the triangles face up, but that’s about all I know.
Now, when assigning each material to each face of the cube, I’m having issues with the sides, the top appears fine, but the sides appear to be stretching the very edge of the texture.

Images to make it a little easier to understand:

The top image is simply a green picture (for grass), the sides show an edge of grass, the rest dirt, like so:

4979-grasssides.png

And when applying everything to my triangles, the sides appear like so:

4978-theproblem.png

I think it may be that my UVs are set improperly, or something of that nature, but this has me stumped and no google searches have yielded any answers.

Thanks in advance,
Perdog

For multiple meshes you have to set multiple submeshes on the Mesh (with corresponding triangles) and then you can set multiple materials on renderer for each submesh.