포탈 생성
This commit is contained in:
27
Assets/Scripts/GameBase/Portal.cs
Normal file
27
Assets/Scripts/GameBase/Portal.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user