IEnumerator addRoom(int xPos, int yPos, Room sourceRoom, Tile.Direction dir){ if (sourceRoom != null) { //audioSource.clip = runeSound; runeSoundSource.Play (); sourceRoom.doRuneAnimations (); } yield return null; while (areAnyAnimationsOccurring ()) { yield return null; } GameObject roomObj = Instantiate (sourceRoom==null ? firstRoomPrefab : roomPrefab, transform.position, Quaternion.identity) as GameObject; Room thisRoom = roomObj.GetComponent<Room> (); thisRoom.setup (xPos, yPos, this); //audioSource.clip = revealSound; revealSoundSource.Play (); if (sourceRoom != null) { int runeSeedFromCurRoom = sourceRoom.getSeedFromRunes (); thisRoom.seedRoom (runeSeedFromCurRoom); } else { thisRoom.seedFirstRoom (); //add the player thisRoom.addTileToGrid (playerTilePrefab, 1, 1); playerTile = (TilePlayer) thisRoom.Grid [1, 1]; playerTile.manager = this; } yield return null; while (areAnyAnimationsOccurring ()) { yield return null; } rooms.Add (thisRoom); //if there was a source room, we shoudl move the player if possible if (sourceRoom != null) { rooms [rooms.Count - 1].tryToMovePlayerToRoom (playerTile, dir); } }