private void Update() { float distance = Vector3.Distance(target.position, transform.position); if (distance <= agent.stoppingDistance) { attackTimer += Time.deltaTime; } else { attackTimer = 0; } if (distance <= agent.stoppingDistance && attackTimer > attackTimeFrequency && !isDead) { DoDamageToPlayer(); enemyAnimation.PlayAttack(); attackTimer = 0f; } enemyAnimation.SetRunSpeed(!(agent.velocity.x == 0 && agent.velocity.y == 0 && agent.velocity.z == 0) ? 1f : 0f); hitTimer += Time.deltaTime; rb.position = transform.position; }