# I need help with a dungeon generator

I’m working on a cave generator for my game, and so far I got it to place cubes, but I want to know how to make it so you can walk in the system of cubes. Also if this makes thing any different your feet always face a collider (Kind of like super mario galaxy).
Here’s my code:

`````` #pragma strict
//thing being generated
var cube : GameObject;

//if you can generate
var allowGen: boolean = true;

function Start () {

transform.position = Vector3(0,0,0);
}

function Update () {
// runs the generate function
Gen();

}

function Gen(){
var i : int = 0;
var cube = cube;
var x : int;
//how many cubes to place
var cubesToPlace: int;

cubesToPlace = 100;
if(allowGen)
{
for(i=0; i<5; i++)
{
transform.position.x += 1;
Instantiate(cube,transform.position,transform.rotation);
}
for(x=0;x<cubesToPlace;x++)
{
var roll : int;
var checkRoll : int;
roll = Random.Range(1,6);
if(roll != checkRoll)
{
if(roll == 1)
{
transform.position.x +=1;
}
else if(roll == 2)
{
transform.position.x -=1;
}
else if(roll == 3)
{
transform.position.y +=1;
}
else if(roll == 4)
{
transform.position.y -=1;
}
else if(roll == 5)
{
transform.position.z +=1;
}
else if(roll == 6)
{
transform.position.z -=1;
}
Instantiate(cube,transform.position,transform.rotation);
roll = checkRoll;

}
else
{
return;
}

}
allowGen = false;
}

}
``````

Instead of placing cubes, use a 3d or 2d array system and place empty and filled bits on it, then loop over the whole array while checking the aligned bits on the array, then use procedurally created meshes to make the hallways etc. or just place walls and floors and ceilings (prefabs or game objects) on the array bits that need it.

Hope this solves it a bit.