Well i have been messing around with terrain generation with cubes, i wanted to work on the logic first so i know what i need to change something for graphics i can easily do it because all the logic will be already here
I have made a GameObject[ ] array and its objects depend on a integer called cube what starts at 0
the code is here
public int mapX;
public int mapY = 2;
public int mapZ;
public int mapXMax = 100;
public int mapZMax = 100;
public int mapXMinimum = 10;
public int mapZMinimum = 10;
private GameObject[ ] cubes;
private GameObject terrain;
private int cube = 0;
void Start () {
mapX = 10;
mapZ = 10;
cubes = new GameObject[mapX * mapY * mapZ];
for (int x = 0; x < mapX; x++) {
Debug.Log("cubes: " + cubes.Length + " cube: " + cube);
cubes[cube] = GameObject.CreatePrimitive(PrimitiveType.Cube);
cubes[cube].transform.localPosition = new Vector3(x, 0, 0);
cubes[cube].transform.localScale = new Vector3(1, 1, 1);
cube += 1;
for (int y = 0; y < mapY; y++) {
Debug.Log("cubes: " + cubes.Length + " cube: " + cube);
cubes[cube] = GameObject.CreatePrimitive(PrimitiveType.Cube);
cubes[cube].transform.localPosition = new Vector3(x, y, 0);
cubes[cube].transform.localScale = new Vector3(1, 1, 1);
cube += 1;
for (int z = 0; z < mapZ; z++) {
Debug.Log("cubes: " + cubes.Length + " cube: " + cube);
cubes[cube] = GameObject.CreatePrimitive(PrimitiveType.Cube);
cubes[cube].transform.localPosition = new Vector3(x, y, z);
cubes[cube].transform.localScale = new Vector3(1, 1, 1);
cube += 1;
}
}
}
I know 10 * 10 * 2 is 200 but it seems that this nested for loop creates 229 cubes for some reason, i cant seem to find the problem with this and iv tried everything i can, even going as far as xyz having their own loops and that didnt work
I would love it if i could get some help on this