// this REQUIRES that the memos are placed in such a way that players can NEVER pick them up from inside the trigger zone IEnumerator roomSwitch() { // close door doorClosing = true; Door.Instance.TryCloseDoor(); yield return(new WaitWhile(() => Door.Instance.Open)); doorClosing = false; // switch rooms currentRoom.Despawn(); if (destroyCurrentRoomOnSwitch) { destroyCurrentRoomOnSwitch = false; Destroy(currentRoom.gameObject); // ... onSwitch } currentRoom = waitingRoom; currentRoomDir = currentRoomDir.Flipped(); if (pooledRooms.Count > 0) { nextRoomIndex = (int)Mathf.Repeat(nextRoomIndex + 1, pooledRooms.Count); var nextPrefab = pooledRooms[nextRoomIndex]; waitingRoom = nextPrefab.Respawn(currentRoomDir.Flipped()); } nextIsBedroom = false; currentRoomTrigger = currentRoomDir.IsPositive() ? FrontTrigger : BackTrigger; waitingRoomTrigger = currentRoomDir.IsNegative() ? FrontTrigger : BackTrigger; }
void Start() { Memo.MemoPickedUp += onMemoPickedUp; pooledRooms = new List <Room>(RoomPrefabs.Count); for (int i = 0; i < RoomPrefabs.Count; i++) { pooledRooms.Add(Instantiate(RoomPrefabs[i])); pooledRooms[i].Despawn(); } Bedroom = Room.Initialize(Bedroom, currentRoomDir); currentRoom = Bedroom; waitingRoom = pooledRooms[nextRoomIndex].Respawn(currentRoomDir.Flipped()); currentRoomTrigger = BackTrigger; waitingRoomTrigger = FrontTrigger; }