I am making a tile map with 3D cubes. It’s generated through a script, and can be expanded by changing some values and I want to make a wall around that tilemap, but I don’t know how to script that. I tried hard-coding it, but the problem is, that the tilemap will be expandable to different directions, so I can’t do that. So how do I make a wall around the tilemap with script?
if its a square or rectangle you can do something like this:
float i;
Color c;
int d;
int w;
int height;
GameObject g;
Vector3 pos;
float scale;
void Start () {
height = 5;//block height of wall
w = 23;//<<this is how many cubes wide
d = 10;//<<this is how many cubes deep
pos = new Vector3(1,1,1);//<<this is your start position
scale = 2;//<<this is your scale
while(height>0){height--;
i = d;
while (i>1) {i--;
block(new Vector3(i,height,0));
block(new Vector3(i-1,height,(float)w-1));}
i = w;
while (i>1) {i--;
block(new Vector3(0,height,i-1));
block(new Vector3((float)d-1,height,i));}}}
void block(Vector3 v){
g = GameObject.CreatePrimitive (PrimitiveType.Cube);
g.transform.position = v*scale+pos;
g.transform.localScale = Vector3.one * scale;
c = new Color (Random.Range (0f, 1f),Random.Range (0f, 1f),Random.Range (0f, 1f), 1);
g.transform.renderer.material.color = c;
}
if you have irregular shaped floors there is an algorithm for that !!! The same algorithym that a paint program would use to “flood fill” a texture would also find all your needed wall locations!!! if you can post some sort of code example of how you are setting up, I can post a code example how to implement it in your situation.