initial room transitioning
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// Handle room and scene transitions
|
||||
public class TeleportHandler : MonoBehaviour
|
||||
{
|
||||
public Image blackScreenObject;
|
||||
PlayerController playerController;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playerController = GetComponent<PlayerController>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the room entrance coroutine, only works if the character is not controllable (keeps from double transitioning)
|
||||
/// </summary>
|
||||
public void EnterRoom(RoomDoor door)
|
||||
{
|
||||
if (playerController.GetCharacterHasControl())
|
||||
StartCoroutine(EnterRoomCoroutine(door));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle teleportation and timing for entering rooms within a scene
|
||||
/// </summary>
|
||||
IEnumerator EnterRoomCoroutine(RoomDoor door)
|
||||
{
|
||||
float fadeDuration = 0.2f;
|
||||
float fadeTime = 0;
|
||||
Color blackScreenColor = Color.black;
|
||||
|
||||
playerController.SetCharacterControl(false);
|
||||
// Play enter room animation (wait seconds during animation)
|
||||
if (door.requiresInteraction)
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
blackScreenObject.gameObject.SetActive(true);
|
||||
while (fadeTime < fadeDuration)
|
||||
{
|
||||
blackScreenColor.a = Mathf.Lerp(0, 1, fadeTime / fadeDuration);
|
||||
blackScreenObject.color = blackScreenColor;
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
fadeTime = 0;
|
||||
|
||||
transform.position = door.linkedDoor.transform.position;
|
||||
playerController.DougBody.transform.rotation = door.linkedDoor.transform.rotation;
|
||||
|
||||
while (fadeTime < fadeDuration)
|
||||
{
|
||||
blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration);
|
||||
blackScreenObject.color = blackScreenColor;
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
fadeTime = 0;
|
||||
|
||||
blackScreenObject.gameObject.SetActive(false);
|
||||
|
||||
// Play exit animation for linked door (if it exists)
|
||||
door.linkedDoor.CloseDoor();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
playerController.SetCharacterControl(true);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user