Hello,
so I have this level array script but I just could figure out how to add more tiles. When I got it to work it placed every tiles twice as much. I know it has something to with the else statement but I just can’t figure out what it is, because when I only copy the if and not the else with it, it still makes twice as much tiles. Already thanks for your help
var blockPiece1 : GameObject;
var blockPiece2 : GameObject;
var levelArray:int[] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,1,1,1,1,0,1,1,1,1,1,0,0,0,0,1,
1,0,0,0,1,1,1,1,1,0,1,1,0,1,1,1,0,0,0,1,
1,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,1,
1,0,0,0,1,1,1,1,1,0,0,1,1,0,1,1,0,0,0,1,
1,0,0,0,0,1,1,1,1,1,0,1,1,1,1,0,0,0,0,1,
1,0,0,0,0,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
var width = 20;
var length = 20;
var pieces: GameObject[ , ];
function Awake() {
pieces = new GameObject[width, length]; // creates the object array
for(x=0; x<width; x++){
for(z=0; z<length; z++){
print("x: " + x + " z: " + z + " type: " + levelArray[z*20 + x]);
var prefab: GameObject;
if(levelArray[z*20 + x] == 1)
prefab = blockPiece1;
else
prefab = blockPiece2;
pieces[x,z] = Instantiate (prefab, Vector3(x,1,z), Quaternion.identity);
pieces[x,z].name = "tiles";
}
}
}