Teleport Player to an object

One way…
Portkey (Harry Potter’s teleportation magic):

  • Create your touch-me-get-teleported GameObject with a Trigger Collider (e.g., a sphere or box collider).
  • Make sure “Is Trigger” is checked in the Collider settings.
  • Attach the Portkey script to this GameObject.
  • Assign a Transform to targetLocation. This will be the destination where the player teleports.

Script:

using UnityEngine;


class Portkey : MonoBehaviour
{
    public Transform targetLocation;

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            other.transform.position = targetLocation.position;
        }
    }
}

Your player must have:

  • A Collider component
  • A Rigidbody component (so Unity can detect trigger collisions)
  • The tag set to “Player”