diff --git a/Assets/Scripts/EnemyAIController.cs b/Assets/Scripts/EnemyAIController.cs index 5ef8b68..6cb5853 100644 --- a/Assets/Scripts/EnemyAIController.cs +++ b/Assets/Scripts/EnemyAIController.cs @@ -916,6 +916,16 @@ namespace Northbound switch (state) { case EnemyAIState.Idle: + _agent.isStopped = true; + _agent.ResetPath(); + // 즉시 정지를 위해 velocity 초기화 + _agent.velocity = Vector3.zero; + // 복귀 완료 - 무적 해제 + if (_enemyUnit != null) + { + _enemyUnit.SetInvulnerable(false); + } + break; case EnemyAIState.Attack: _agent.isStopped = true; _agent.ResetPath(); @@ -940,6 +950,12 @@ namespace Northbound _agent.isStopped = false; _agent.speed = moveSpeed; _agent.SetDestination(_originPosition); + // 복귀 시작 - 체력 회복 및 무적 + if (_enemyUnit != null) + { + _enemyUnit.HealToFull(); + _enemyUnit.SetInvulnerable(true); + } break; case EnemyAIState.Dead: _agent.isStopped = true; diff --git a/Assets/Scripts/EnemyUnit.cs b/Assets/Scripts/EnemyUnit.cs index 9e20b62..749d3c2 100644 --- a/Assets/Scripts/EnemyUnit.cs +++ b/Assets/Scripts/EnemyUnit.cs @@ -36,6 +36,12 @@ namespace Northbound NetworkVariableWritePermission.Server ); + private NetworkVariable _isInvulnerable = new NetworkVariable( + false, + NetworkVariableReadPermission.Everyone, + NetworkVariableWritePermission.Server + ); + /// /// 사망 시 발생하는 이벤트 (매개변수: killerId) /// @@ -106,6 +112,9 @@ namespace Northbound if (!IsServer) return; if (_currentHealth.Value <= 0) return; + // 무적 상태면 데미지 무시 + if (_isInvulnerable.Value) return; + // 공격자의 팀 확인 if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(attackerId, out NetworkObject attackerObj)) { @@ -207,6 +216,24 @@ namespace Northbound #endregion + #region Invulnerability & Healing + + public bool IsInvulnerable() => _isInvulnerable.Value; + + public void SetInvulnerable(bool value) + { + if (!IsServer) return; + _isInvulnerable.Value = value; + } + + public void HealToFull() + { + if (!IsServer) return; + _currentHealth.Value = maxHealth; + } + + #endregion + private void OnDrawGizmosSelected() { #if UNITY_EDITOR