using UnityEngine; public class ConstructionSite : MonoBehaviour { private GameObject _finalPrefab; private float _buildTime; private float _timer; private Vector3Int _gridPos; private bool _isCompleted = false; // 중복 완공 방지 플래그 public void Initialize(GameObject final, float time, Vector3Int pos) { _finalPrefab = final; _buildTime = time; _gridPos = pos; _timer = 0; _isCompleted = false; } void Update() { if (_isCompleted) return; // 매 프레임 자동으로 시간이 흐름 _timer += Time.deltaTime; if (_timer >= _buildTime) Complete(); } // [핵심] 플레이어가 상호작용 버튼을 꾹 누를 때 호출되는 함수 public void AdvanceConstruction(float amount) { if (_isCompleted) return; _timer += amount; if (_timer >= _buildTime) Complete(); } private void Complete() { // 1. 터널 생성 GameObject tunnel = Instantiate(_finalPrefab, transform.position, Quaternion.identity); TunnelNode node = tunnel.GetComponentInChildren(); if (node != null) { // 2. [수정] 완공된 터널의 루트 위치로 좌표 계산 Vector3Int myGridPos = BuildManager.Instance.WorldToGrid3D(tunnel.transform.position); // 3. 레지스트리 등록 및 연결 BuildManager.Instance.RegisterTunnel(myGridPos, node); node.LinkVertical(); } Destroy(gameObject); } }