public void GenerateDungeon() { foreach (Transform child in transform) { Destroy(child.gameObject); } foreach (GameObject obj in trees) { obj.SetActive(false); } rooms = new Room[roomAmount]; paths = new DungeonPath[roomAmount - 1]; //generate positions and sizes for each room; generation should be done in the room itself, will work on that for (int k = 0; k < roomAmount; k++) { int roomWidth = Random.Range(roomMinWidth, roomMaxWidth); int roomHeight = Random.Range(roomMinHeight, roomMaxHeight); int roomX = Random.Range(0, areaWidth - roomWidth); int roomZ = Random.Range(0, areaHeight - roomHeight); GameObject room = new GameObject { name = "Room " + (k + 1) }; room.transform.parent = transform; room.gameObject.tag = "Room"; rooms[k] = room.AddComponent <Room>(); rooms[k].MakeRoom(roomWidth, roomHeight, roomX, roomZ); //create a path for every room; but skip the first as it doesnt have a neighbor yet if (k > 0) { GameObject path = new GameObject { name = "Path " + (k) }; path.transform.parent = rooms[k - 1].transform; paths[k - 1] = path.AddComponent <DungeonPath>(); rooms[k].paths.Add(paths[k - 1]); paths[k - 1].CreatePath(rooms[k - 1], rooms[k]); } } SetTiles(); spawnScript.SpawnPlayerAt(rooms[0].GetCenter()); }