Files
ProjectMD/Assets/Scripts/TunnelNode.cs
Dal4segno d6292b6879 멀티플레이어 지원
이동, 건설, 인터랙션, 공격 등
2026-01-16 19:30:26 +09:00

41 lines
1.4 KiB
C#

using UnityEngine;
using Unity.Netcode;
public class TunnelNode : NetworkBehaviour, IInteractable
{
public TunnelNode aboveNode;
public TunnelNode belowNode;
public override void OnNetworkSpawn()
{
// 모든 클라이언트에서 각자 장부에 등록
Vector3Int myPos = BuildManager.Instance.WorldToGrid3D(transform.position);
BuildManager.Instance.RegisterTunnel(myPos, this);
// 모든 노드가 등록될 시간을 벌기 위해 서버에서 약간 지연 후 연결 명령
if (IsServer) Invoke(nameof(SyncLinks), 0.2f);
}
private void SyncLinks() => LinkVerticalRpc();
[Rpc(SendTo.Everyone)]
private void LinkVerticalRpc() => LinkVertical();
public void LinkVertical()
{
Vector3Int myPos = BuildManager.Instance.WorldToGrid3D(transform.position);
aboveNode = BuildManager.Instance.GetTunnelAt(myPos + Vector3Int.up);
belowNode = BuildManager.Instance.GetTunnelAt(myPos + Vector3Int.down);
if (aboveNode != null) aboveNode.belowNode = this;
if (belowNode != null) belowNode.aboveNode = this;
}
public void Interact(GameObject user)
{
var traveler = user.GetComponent<TunnelTraveler>();
if (traveler && !traveler.IsTraveling) traveler.StartTravel(this);
}
public string GetInteractionText() => "터널 이용 [E]";
}