Creating portals

Hi,

I am trying to make a portal like the following video, however, when I turn the receiving portal by 90 degree, the player is teleported but the direction of the camera did not rotate accordingly (i.e. by 90 degree). How should I modify the following code for that? I am a beginner in Unity please help.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TeleportPlane2 : MonoBehaviour
{

    public Transform player;
    public Transform receiver;

    private bool playerIsOverlapping = false;

    // Update is called once per frame
    void Update()
    {
        if (playerIsOverlapping)
        {
            Vector3 portalToPlayer = player.position - transform.position;
            float dotProduct = Vector3.Dot(transform.up, portalToPlayer);

            //If this is true: The player has moved across the portal
            if (dotProduct < 0f)
            {
                //Teleport him!
                float rotationDiff = -Quaternion.Angle(transform.rotation, receiver.rotation);
                rotationDiff += 180;
                player.Rotate(Vector3.up, rotationDiff);

                Vector3 positionOffset = Quaternion.Euler(0f, rotationDiff, 0f) * portalToPlayer;
                player.position = receiver.position + positionOffset;

                playerIsOverlapping = false;


            }
        }
    }

    void OnTriggerEnter(Collider collider)
    {
        if (collider.name == "Player")
        {
            playerIsOverlapping = true;
        }
    }
    void OnTriggerExit(Collider collider)
    {
        if (collider.name == "Player")
        {
            playerIsOverlapping = false;
        }

    }
}

I’ve answered questions to this very same tutorial multiple times now… funny.

Like here:

And here was the original time I did:

Here’s even a fork I did of the original project and made the appropriate changes so the code from the tutorial ACTUALLY works:

Cause yeah, the tutorial was written badly.