타워 자동 공격 시스템 수정

이전 타워 수정의 사이드 이펙트
미사용 SO 제거
This commit is contained in:
2026-02-01 19:09:39 +09:00
parent 4253271d84
commit 78791649ae
8 changed files with 75 additions and 85 deletions

View File

@@ -9,33 +9,27 @@ namespace Northbound
public class AutoTargetSystem : NetworkBehaviour
{
[Header("Targeting")]
[Tooltip("적을 감지하는 범위")]
public float detectionRange = 15f;
[Tooltip("공격 가능한 범위")]
public float attackRange = 10f;
[Tooltip("공격 간격 (초)")]
public float attackInterval = 1f;
[Tooltip("탐지할 레이어")]
public LayerMask targetLayer = ~0;
[Header("Combat")]
[Tooltip("공격 데미지")]
public int attackDamage = 10;
[Header("Debug")]
[Tooltip("디버그 정보 표시")]
public bool showDebugInfo = true;
private Building _building;
private ITeamMember _teamMember;
private float _lastAttackTime;
private void Awake()
{
_building = GetComponent<Building>();
_teamMember = GetComponent<ITeamMember>();
if (_building == null)
{
Debug.LogError($"<color=red>[AutoTargetSystem] {gameObject.name}에 Building 컴포넌트가 없습니다!</color>");
}
if (_teamMember == null)
{
Debug.LogError($"<color=red>[AutoTargetSystem] {gameObject.name}에 ITeamMember 컴포넌트가 없습니다!</color>");
@@ -45,9 +39,9 @@ namespace Northbound
private void Update()
{
if (!IsServer) return;
if (_teamMember == null) return;
if (_building == null || _teamMember == null) return;
if (Time.time - _lastAttackTime >= attackInterval)
if (Time.time - _lastAttackTime >= _building.buildingData.atkIntervalSec)
{
FindAndAttackEnemy();
}
@@ -55,6 +49,10 @@ namespace Northbound
private void FindAndAttackEnemy()
{
float detectionRange = _building.buildingData.atkRange;
float attackRange = _building.buildingData.atkRange;
int attackDamage = _building.buildingData.atkDamage;
// 범위 내 모든 콜라이더 탐지
Collider[] colliders = Physics.OverlapSphere(transform.position, detectionRange, targetLayer);
@@ -152,13 +150,17 @@ namespace Northbound
private void OnDrawGizmos()
{
if (_building == null || _building.buildingData == null) return;
float range = _building.buildingData.atkRange;
// 탐지 범위 (노란색)
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, detectionRange);
Gizmos.DrawWireSphere(transform.position, range);
// 공격 범위 (빨간색)
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, attackRange);
Gizmos.DrawWireSphere(transform.position, range);
}
private void OnDrawGizmosSelected()
@@ -166,10 +168,10 @@ namespace Northbound
OnDrawGizmos();
#if UNITY_EDITOR
if (_teamMember != null && Application.isPlaying)
if (_teamMember != null && _building != null && _building.buildingData != null && Application.isPlaying)
{
UnityEditor.Handles.Label(transform.position + Vector3.up * 3f,
$"Auto Target\nTeam: {TeamManager.GetTeamName(_teamMember.GetTeam())}\nDetection: {detectionRange}m\nAttack: {attackRange}m");
$"Auto Target\nTeam: {TeamManager.GetTeamName(_teamMember.GetTeam())}\nRange: {_building.buildingData.atkRange}m\nDamage: {_building.buildingData.atkDamage}");
}
#endif
}