using System; using UnityEngine; namespace Escape_Room_Engine.Portal { public class Portal : MonoBehaviour { /// /// The portal that is connected with this one. /// public Portal other; /// /// The main camera to take the position for the portal camera from. /// [SerializeField] private Transform playerCamera; /// /// The camera that will draw the view for this portal. /// [SerializeField] private Transform portalCamera; private void Start() { // check whether the other portal is set up if (!other || other.other != this) throw new Exception("Other Portal not set up correctly."); // check whether the player camera is set up if (!playerCamera) throw new Exception("No camera initialised."); } private void Update() { var portalCameraMatrix = transform.localToWorldMatrix * other.transform.worldToLocalMatrix * playerCamera.localToWorldMatrix; portalCamera.SetPositionAndRotation(portalCameraMatrix.GetPosition(), portalCameraMatrix.rotation); } } }