public MazeMP GenerateMaze() { MazeGeneratorCellMP[,] cells = new MazeGeneratorCellMP[Width, Height]; for (int x = 0; x < cells.GetLength(0); x++) { for (int y = 0; y < cells.GetLength(1); y++) { cells[x, y] = new MazeGeneratorCellMP { X = x, Y = y }; } } for (int x = 0; x < cells.GetLength(0); x++) { cells[x, Height - 1].WallLeft = false; } for (int y = 0; y < cells.GetLength(1); y++) { cells[Width - 1, y].WallBottom = false; } RemoveWallsWithBacktracker(cells); MazeMP maze = new MazeMP(); maze.cells = cells; maze.finishPosition = PlaceMazeExit(cells); return(maze); }
private void Start() { MazeGeneratorMP generator = new MazeGeneratorMP(); maze = generator.GenerateMaze(); for (int x = 0; x < maze.cells.GetLength(0); x++) { for (int y = 0; y < maze.cells.GetLength(1); y++) { Cell c = Instantiate(CellPrefab, new Vector3(x * CellSize.x, y * CellSize.y, y * CellSize.z), Quaternion.identity); c.WallLeft.SetActive(maze.cells[x, y].WallLeft); c.WallBottom.SetActive(maze.cells[x, y].WallBottom); } } Instantiate(Resources.Load("EndOfMaze", typeof(GameObject)) as GameObject, new Vector3(maze.finishPosition.x * 10 + 5, 5, maze.finishPosition.y * 10 + 5), Quaternion.identity); }