I am trying to make a Minecraft like game. I managed to create a mesh of a cube using vertices and triangles. I am wondering if there was a way to put them in a 16 by 16 grid?
In start I wrote:
for (int z = 0; z<= zSize; z++)
{
for (int z = 0; z<= zSize; z++)
{
}
}
I just want to put this code in it:
void CreateCube ()
{
Vector3[] vertices = {
new Vector3 (0, 0, 0),
new Vector3 (1, 0, 0),
new Vector3 (1, 1, 0),
new Vector3 (0, 1, 0),
new Vector3 (0, 1, 1),
new Vector3 (1, 1, 1),
new Vector3 (1, 0, 1),
new Vector3 (0, 0, 1),
};
int[] triangles = {
0, 2, 1, //face front
0, 3, 2,
2, 3, 4, //face top
2, 4, 5,
1, 2, 5, //face right
1, 5, 6,
0, 7, 4, //face left
0, 4, 3,
5, 4, 7, //face back
5, 7, 6,
0, 6, 7, //face bottom
0, 1, 6
};
Mesh mesh = GetComponent<MeshFilter> ().mesh;
mesh.Clear ();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.Optimize ();
mesh.RecalculateNormals ();
}
Is it possible to do something like: for (int z = 0; z<= zSize; z++) { for (int z = 0; z<= zSize; z++) { Instantiate(cube, new Vector3(x,0,y); } } And then in another script edit the cube so that only the faces that are exposed to air are shown?
– Bl00dyFish