using UnityEngine; public class Teleporter : MonoBehaviour { [Header("Target Destination")] public Transform destination; // จุดหมายปลายทางที่จะวาร์ปไป private void OnTriggerEnter(Collider other) { // เช็กว่าวัตถุที่เดินเข้ามาชนมี Tag เป็น Player หรือไม่ if (other.CompareTag("Player")) { // หากตัวละครใช้ CharacterController ต้องปิดก่อนย้ายตำแหน่ง CharacterController cc = other.GetComponent(); if (cc != null) { cc.enabled = false; other.transform.position = destination.position; other.transform.rotation = destination.rotation; cc.enabled = true; } else { // ย้ายตำแหน่งตัวละครปกติ other.transform.position = destination.position; other.transform.rotation = destination.rotation; } } } }