# Help building structures with cubes using code.

Hi. I am trying to do a small experiment in which I would like to build structures with simple cubes using code.

I found this code on GitHub, which makes some simple trees:

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class Structure
{
public static void MakeTree(Vector3 position, Queue<VoxelMod> queue, int minTrunkHeight, int maxTrunkHeight)
{
int height = (int)(maxTrunkHeight * Noise.Get2DPerlin(new Vector2(position.x, position.z), 250f, 3f));

if (height < minTrunkHeight)
{
height = minTrunkHeight;
}

for (int i = 1; i < height; i++)
{
queue.Enqueue(new VoxelMod(new Vector3(position.x, position.y + i, position.z), 6));
}

//leaves

for (int x = -2; x < 3; x++)
{
for (int z = -2; z < 3; z++)
{
queue.Enqueue(new VoxelMod(new Vector3(position.x + x, position.y + height - 2, position.z + z), 11));
queue.Enqueue(new VoxelMod(new Vector3(position.x + x, position.y + height - 3, position.z + z), 11));
}
}

for (int x = -1; x < 2; x++)
{
for (int z = -1; z < 2; z++)
{
queue.Enqueue(new VoxelMod(new Vector3(position.x + x, position.y + height - 1, position.z + z), 11));
}
}
for (int x = -1; x < 2; x++)
{
if (x == 0)
for (int z = -1; z < 2; z++)
{
queue.Enqueue(new VoxelMod(new Vector3(position.x + x, position.y + height, position.z + z), 11));
}
else
queue.Enqueue(new VoxelMod(new Vector3(position.x + x, position.y + height, position.z), 11));
}

}
}
``````

I have tested the whole project (which is on GitHub) and it works, but I canâ€™t understand how it works. If someone can explain it to me I would appreciate it a lot to be able to make my own structures.

bump

bump