- Home /
How do I make a grid of custom meshes?
Please note that I have some experience with coding, but only just started using Unity. So I'm trying to make a game like Minecraft, and I want to make a grid of cubes. The reason I use custom cubes is so I can later hide the invisible meshes. So far, I made a cube following a tutorial I modified.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class VoxelData : MonoBehaviour
{
Mesh mesh;
Vector3[] vertices;
int[] triangles;
// Start is called before the first frame update
void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
CreateShape();
UpdateMesh();
}
void CreateShape()
{
vertices = new Vector3[]
{
new Vector3 (0, 0, 0),//0
new Vector3 (0, 0, 1),//1
new Vector3 (1, 0, 0),//2
new Vector3 (1, 0, 1),//3
new Vector3 (0, 1, 0),//4
new Vector3 (0, 1, 1),//5
new Vector3 (1, 1, 0),//6
new Vector3 (1, 1, 1)//7
};
triangles = new int[]
{
4, 5, 6, 6, 5, 7, //top
0, 4, 2, 2, 4, 6, //front
2, 6, 3, 3, 6, 7, //right
1, 5, 0, 0, 5, 4, //left
3, 7, 1, 1, 7, 5, //back
2, 3, 0, 0, 3, 1 //bottom
};
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
}
}
//Credit goes to Brackeys for the tutorial for making meshes
Now I want to make a grid of these cubes, but I'm struggling with making it. How would I go about doing this? Thanks in advance.
Comment
Your answer

Follow this Question
Related Questions
Board Game Grid 0 Answers
How do you save a seed? 1 Answer
Sorting the children of a Grid Layout in 4.6 UI 3 Answers
Manual Collision Detection through triggers... 0 Answers
fixed angle grid movement issue 1 Answer