public List <List <CubeInfo> > BuildCubes() { List <List <CubeInfo> > currentCubes = new List <List <CubeInfo> >(); for (int h = 1; h < cubesAmountY + 1; h++) { if ((h * posY) + ((h - 1) * posY) + cubeUnitSize - posY + marginUnitSize / 2 > resolutionHeight) { continue; } currentCubes.Add(new List <CubeInfo>()); for (int w = 1; w < cubesAmountX + 1; w++) { if ((w * posX) + ((w - 1) * posX) + cubeUnitSize - posX + marginUnitSize / 2 > resolutionWidth) { continue; } GameObject cube = Instantiate( cubes, new Vector3(transform.position.x + (w * posX) + ((w - 1) * posX), transform.position.x + (h * posY) + ((h - 1) * posY), cubeUnitSize / 2), cubes.transform.rotation ); cube.transform.localScale = new Vector3(cubeUnitSize, cubeUnitSize, cubeUnitSize); cube.SetActive(false); CubeInfo cubeInfo = new CubeInfo(); cubeInfo.SetGameOBJ(cube); cubeInfo.SetIsAlive(false); currentCubes[h - 1].Add(cubeInfo); } } for (int x = 0; x < currentCubes.Count; x++) { for (int y = 0; y < currentCubes[x].Count; y++) { if (x == 0 || y == 0 || x == currentCubes.Count - 1 || y == currentCubes[x].Count - 1) { SetCubeColor(currentCubes[x][y].gameOBJ, Color.black); } else { if (Random.Range(0, 1000) < seed) { currentCubes[x][y].SetIsAlive(true); SetCubeColor(currentCubes[x][y].gameOBJ, orange); } else { SetCubeColor(currentCubes[x][y].gameOBJ, black); } } } } return(currentCubes); }