using UnityEngine; using System.Collections; using System.Collections.Generic; public class TunnelTraveler : MonoBehaviour { public float travelSpeed = 20f; private bool _isTraveling; public bool IsTraveling => _isTraveling; public void StartTravel(TunnelNode start) { if (_isTraveling) return; // [디버그 1] 상호작용한 노드의 연결 상태 확인 Debug.Log($"[Travel] 시작 노드: {start.name} | 위: {(start.aboveNode != null)} | 아래: {(start.belowNode != null)}"); List path = new List(); // 이동 방향 결정 (아래가 있으면 아래로, 없으면 위로) bool goDown = start.belowNode != null; TunnelNode curr = goDown ? start.belowNode : start.aboveNode; while (curr != null) { path.Add(curr.transform.position); curr = goDown ? curr.belowNode : curr.aboveNode; } // [디버그 2] 최종 경로 개수 확인 Debug.Log($"[Travel] 생성된 경로 포인트 개수: {path.Count}"); if (path.Count > 0) { StartCoroutine(Travel(path)); } else { Debug.LogWarning("[Travel] 이동할 경로가 없습니다! 노드 연결을 확인하세요."); } } private IEnumerator Travel(List path) { Debug.Log("[Travel] 코루틴 이동 시작!"); _isTraveling = true; var cc = GetComponent(); if (cc) cc.enabled = false; foreach (var point in path) { Vector3 target = new Vector3(point.x, point.y - (cc ? cc.height / 2 : 0), point.z); while (Vector3.Distance(transform.position, target) > 0.1f) { transform.position = Vector3.MoveTowards(transform.position, target, travelSpeed * Time.deltaTime); yield return null; } transform.position = target; } if (cc) cc.enabled = true; _isTraveling = false; Debug.Log("[Travel] 이동 완료!"); } }