using UnityEngine; public class PlayerTeleport : MonoBehaviour { private GameObject currentTeleporter; private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Teleporter")) { currentTeleporter = collision.gameObject; Teleport(); } } private void OnTriggerExit2D(Collider2D collision) { if (collision.CompareTag("Teleporter") && collision.gameObject == currentTeleporter) { currentTeleporter = null; } } private void Teleport() { if (currentTeleporter != null) { transform.position = currentTeleporter.GetComponent().GetDestination().position; } } }