27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
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)
|
|
{
|
|
// 상대방 포탈의 쿨타임도 같이 설정해야 무한 루프를 방지함
|
|
Portal destPortal = destination.GetComponent<Portal>();
|
|
if (destPortal != null) destPortal._lastTeleportTime = Time.time;
|
|
|
|
_lastTeleportTime = Time.time;
|
|
|
|
// 플레이어 위치 이동
|
|
// CharacterController나 Rigidbody를 사용 중이라면 이동 방식에 주의
|
|
other.transform.position = destination.position;
|
|
|
|
Debug.Log("Teleported to " + destination.name);
|
|
}
|
|
}
|
|
} |