인터랙션 시스템 및 터널 기능 생성
This commit is contained in:
42
Assets/Scripts/TunnelNode.cs
Normal file
42
Assets/Scripts/TunnelNode.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user