터널 연장 로직 개선
This commit is contained in:
@@ -1,35 +1,33 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class PlayerInteractionController : MonoBehaviour
|
||||
{
|
||||
[Header("Detection Settings")]
|
||||
[SerializeField] private float range = 3f;
|
||||
[SerializeField] private LayerMask interactableLayer; // Tunnel용 레이어
|
||||
[SerializeField] private LayerMask constructionLayer; // 건설 토대용 레이어
|
||||
[SerializeField] private LayerMask interactableLayer; // TunnelNode 감지용
|
||||
[SerializeField] private LayerMask constructionLayer; // ConstructionSite 감지용
|
||||
|
||||
[Header("Build Settings")]
|
||||
[SerializeField] private float buildSpeedMultiplier = 2f;
|
||||
|
||||
private PlayerInputActions _inputActions;
|
||||
private bool _isHoldingInteract = false;
|
||||
private TunnelTraveler _traveler;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_inputActions = new PlayerInputActions();
|
||||
_traveler = GetComponent<TunnelTraveler>();
|
||||
|
||||
// 탭(짧게 누르기) 시점 체크
|
||||
_inputActions.Player.Interact.performed += OnInteractTap;
|
||||
// [최신화] 탭/홀드 로직을 Input Action 이벤트에 직접 바인딩
|
||||
// 1. 단일 상호작용 (터널 진입 등)
|
||||
_inputActions.Player.Interact.performed += OnInteractPerformed;
|
||||
|
||||
// 홀드(꾹 누르기) 시작/종료 체크
|
||||
_inputActions.Player.Interact.started += ctx => {
|
||||
_isHoldingInteract = true;
|
||||
Debug.Log("인터랙션 버튼 누르기 시작 (건설 가속 준비)");
|
||||
};
|
||||
_inputActions.Player.Interact.canceled += ctx => {
|
||||
_isHoldingInteract = false;
|
||||
Debug.Log("인터랙션 버튼 뗌");
|
||||
};
|
||||
// 2. 지속 상호작용 (건설 가속)
|
||||
_inputActions.Player.Interact.started += ctx => _isHoldingInteract = true;
|
||||
_inputActions.Player.Interact.canceled += ctx => _isHoldingInteract = false;
|
||||
}
|
||||
|
||||
void OnEnable() => _inputActions.Enable();
|
||||
@@ -37,52 +35,65 @@ public class PlayerInteractionController : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_isHoldingInteract)
|
||||
// 홀드 중일 때만 건설 지원 로직 실행
|
||||
if (_isHoldingInteract && !(_traveler != null && _traveler.IsTraveling))
|
||||
{
|
||||
PerformConstructionSupport();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractTap(InputAction.CallbackContext context)
|
||||
private void OnInteractPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
Debug.Log("E 키 탭 감지! 주변 탐색 시작...");
|
||||
// [로그 1] 버튼 입력 자체가 인식되는지 확인
|
||||
Debug.Log("<color=white>1. E 키 입력 감지됨</color>");
|
||||
|
||||
if (_traveler != null && _traveler.IsTraveling)
|
||||
{
|
||||
Debug.Log("<color=gray>이동 중이라 상호작용 무시됨</color>");
|
||||
return;
|
||||
}
|
||||
|
||||
// [로그 2] 탐색 시작 위치와 범위 확인
|
||||
Debug.Log($"<color=white>2. 탐색 시작 - 위치: {transform.position}, 범위: {range}, 레이어: {interactableLayer.value}</color>");
|
||||
|
||||
// 1. 주변 모든 콜라이더 가져오기 (레이어 마스크 없이 먼저 테스트해보고 싶다면 0 대신 ~0 입력)
|
||||
Collider[] colliders = Physics.OverlapSphere(transform.position, range, interactableLayer);
|
||||
|
||||
Debug.Log($"주변 {interactableLayer.value} 레이어에서 {colliders.Length}개의 오브젝트 감지됨");
|
||||
// [로그 3] 감지된 콜라이더 개수 확인
|
||||
Debug.Log($"<color=cyan>3. 감지된 콜라이더 개수: {colliders.Length}</color>");
|
||||
|
||||
foreach (var col in colliders)
|
||||
{
|
||||
// 2. 인터페이스 찾기 (본인 또는 부모에게서)
|
||||
// [로그 4] 감지된 오브젝트의 이름 출력
|
||||
Debug.Log($"<color=yellow>4. 감지된 오브젝트: {col.name}</color>");
|
||||
|
||||
IInteractable interactable = col.GetComponentInParent<IInteractable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
Debug.Log($"[성공] {col.name}에서 IInteractable 발견! 터널 진입합니다.");
|
||||
Debug.Log("<color=green>5. IInteractable 발견! Interact 실행</color>");
|
||||
interactable.Interact(gameObject);
|
||||
_isHoldingInteract = false; // 이동 중에는 건설 지원 중단
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"[실패] {col.name} 감지되었으나 IInteractable 스크립트가 없음");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PerformConstructionSupport()
|
||||
{
|
||||
// 주변의 건설 토대 감지
|
||||
Collider[] targets = Physics.OverlapSphere(transform.position, range, constructionLayer);
|
||||
|
||||
foreach (var col in targets)
|
||||
{
|
||||
ConstructionSite site = col.GetComponent<ConstructionSite>();
|
||||
// 토대 스크립트 탐색 (부모 또는 본인)
|
||||
ConstructionSite site = col.GetComponentInParent<ConstructionSite>();
|
||||
if (site != null)
|
||||
{
|
||||
// 최신화된 AdvanceConstruction 호출
|
||||
site.AdvanceConstruction(Time.deltaTime * buildSpeedMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 에디터 시각화
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
|
||||
Reference in New Issue
Block a user