Dash tweaks, quality of code

This commit is contained in:
Tomáš Pěnkava
2025-09-05 17:47:06 +02:00
parent 38704518b0
commit a11c5a8dd7
3 changed files with 10 additions and 2 deletions
@@ -15,10 +15,12 @@ public class EnemyAttack : MonoBehaviour
[SerializeField] private Animator animator;
[SerializeField] private NavMeshAgent agent;
private float lastAttackTime = 0f;
private bool canAttack = true;
private bool isAttacking = false;
private float attackCooldownTimer = 0f;
private PlayerSkillHandler skillHandler;
void Start()
{
@@ -29,6 +31,8 @@ public class EnemyAttack : MonoBehaviour
player = playerObject.transform;
}
skillHandler = player.GetComponent<PlayerSkillHandler>();
if (animator == null) animator = GetComponent<Animator>();
if (agent == null) agent = GetComponent<NavMeshAgent>();
@@ -88,7 +92,6 @@ public class EnemyAttack : MonoBehaviour
float angle = Vector3.Angle(forward, directionToPlayer);
// Vìtší tolerance úhlu (zvýšeno z 22.5° na 60°)
return angle <= attackAngle; // Používáme celý attackAngle, ne polovinu
}
@@ -125,8 +128,9 @@ public class EnemyAttack : MonoBehaviour
// Poèkej chvíli pøed aplikováním poškození
yield return new WaitForSeconds(0.3f);
bool playerDashing = skillHandler.IsDashing();
// Aplikuj poškození, pokud je hráè stále v dosahu
if (player != null && Vector3.Distance(transform.position, player.position) <= attackRange * 1.2f)
if (player != null && Vector3.Distance(transform.position, player.position) <= attackRange * 1.2f && !playerDashing)
{
var health = player.GetComponent<HealthManager>();
if (health != null)
@@ -236,6 +236,7 @@ public class EnemyMovement : MonoBehaviour
}
}
/* ========= PATROLLING IN CASE PLAYER IS FAR ========== */
private void GenerateNewPatrolTarget()
{
Vector2 randomCircle = Random.insideUnitCircle * patrolRange;
@@ -266,6 +267,8 @@ public class EnemyMovement : MonoBehaviour
Destroy(gameObject, 2f);
}
/*====== FOR DEBUGGING PURPOSES ONLY ========== */
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;