42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class TunnelNode : MonoBehaviour, IInteractable
|
|
{
|
|
public TunnelNode connectedNode;
|
|
public TunnelNode otherEndOfThisSegment;
|
|
public float detectionRadius = 0.5f;
|
|
public LayerMask tunnelLayer;
|
|
|
|
// --- IInteractable 구현부 ---
|
|
public void Interact(GameObject user)
|
|
{
|
|
// 상호작용한 플레이어의 TunnelTraveler를 찾아 이동 시작!
|
|
TunnelTraveler traveler = user.GetComponent<TunnelTraveler>();
|
|
if (traveler != null)
|
|
{
|
|
traveler.StartTravel(this);
|
|
}
|
|
}
|
|
|
|
public string GetInteractionText()
|
|
{
|
|
return "통로 진입";
|
|
}
|
|
// ----------------------------
|
|
|
|
void Start() => FindNeighborNode();
|
|
|
|
public void FindNeighborNode()
|
|
{
|
|
Collider[] colliders = Physics.OverlapSphere(transform.position, detectionRadius, tunnelLayer);
|
|
foreach (var col in colliders)
|
|
{
|
|
TunnelNode neighbor = col.GetComponent<TunnelNode>();
|
|
if (neighbor != null && neighbor != this && neighbor != otherEndOfThisSegment)
|
|
{
|
|
connectedNode = neighbor;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |