IEnumerator DoorAnimation() { // Freezes player movement player.FreezePlayer(); // Instantiates the NextRoom RoomGenerator newRoomGenerator = FindObjectOfType <DungeonDisplay>() .InstantiateRoom(door.GetNextRoom(currentRoom.GetCurrentRoom())); // Disables Door Animations For the new Room newRoomGenerator.EnableDoorAnimations(false); // Changes the player animation to walk in appropreate direction. if (direction == Cardinal4.Direction.NORTH) { playerAnimator.SetFloat("deltaX", 0); playerAnimator.SetFloat("deltaY", 1); } else if (direction == Cardinal4.Direction.SOUTH) { playerAnimator.SetFloat("deltaX", 0); playerAnimator.SetFloat("deltaY", -1); } //Move player into the door Coroutine a = StartCoroutine(player.MovePlayerToPoint( (Vector2)this.transform.position, player.GetSpeed())); yield return(a); //Update the current room Room nextRoom = door.GetNextRoom(currentRoom.GetCurrentRoom()); currentRoom.SetCurrentRoom(nextRoom); //Moves camera to new room Coroutine b = StartCoroutine(mainCamera.MoveCameraToNewRoom( currentRoom.GetCurrentRoom(), cameraMovementTime)); yield return(b); // Move player out of the door into the room Coroutine c = StartCoroutine(player.MovePlayerToPoint( (Vector2)this.transform.position + Cardinal4.DirectionToVector2(direction, distanceFromDoor), player.GetSpeed())); yield return(c); // Enable Door Animations for the Next Room newRoomGenerator.EnableDoorAnimations(true); // Allow for Player Movement player.UnfreezePlayer(); // Destroy current RoomGenerator Destroy(currentRoomGenerator.gameObject); }
IEnumerator StairAnimation() { // Freezes player Movement player.FreezePlayer(); // Instantiate the next room Room nextRoom = stair.GetNextRoom(currentRoom.GetCurrentRoom()); RoomGenerator newRoomGenerator = FindObjectOfType <DungeonDisplay>().InstantiateRoom(nextRoom); // Initially Disables all Stair Animations newRoomGenerator.EnableStairAnimations(false); // Moves player to the center of the stairs. Coroutine a = StartCoroutine(player.MovePlayerToPoint( (Vector2)this.transform.position, player.GetSpeed())); yield return(a); // Fades the camera to black Coroutine b = StartCoroutine( fader.FadeCanvasGroupDistinct(alphaValuesFadeBlack, timeToFade)); yield return(b); // Moves the camera and player to the next room. player.transform.position = stair.GetStairWorldPosition(nextRoom); mainCamera.SetCameraToNewRoom(nextRoom); // Updates the current room currentRoom.SetCurrentRoom(nextRoom); // Defades the camera Coroutine c = StartCoroutine( fader.FadeCanvasGroupDistinct(alphaValuesFadeReturn, timeToFade)); yield return(c); // Enables stair animations newRoomGenerator.EnableStairAnimations(true); // Destroys current room generator Destroy(GetComponentInParent <RoomGenerator>().gameObject); // Unfreezes the player player.UnfreezePlayer(); }