using UnityEngine; public class Portal : MonoBehaviour { [SerializeField] private Transform destination; // 순간이동할 목적지 (반대편 포탈의 위치) [SerializeField] private float cooldown = 1f; // 연속 이동 방지 쿨타임 private float _lastTeleportTime; private void OnTriggerEnter(Collider other) { // 플레이어 태그 확인 및 쿨타임 체크 if (other.CompareTag("Player") && Time.time > _lastTeleportTime + cooldown) { CharacterController cc = other.GetComponent(); // 1. 상대방 포탈 쿨타임 설정 Portal destPortal = destination.GetComponent(); if (destPortal != null) destPortal._lastTeleportTime = Time.time; _lastTeleportTime = Time.time; // 2. CharacterController 잠시 끄기 (중요!) if (cc != null) cc.enabled = false; // 3. 위치 이동 other.transform.position = destination.position; Debug.Log("Teleported to " + destination.name); // 4. 다시 켜기 if (cc != null) cc.enabled = true; } } }