private void SearchAndAttack() { float distance = Vector3.Distance(transform.position, target.position); stats = GetComponent <EnemyStats>(); stats.AttackSpeed.CurValue -= Time.deltaTime; if (distance <= searchRadius) { agent.SetDestination(target.position); if (distance <= agent.stoppingDistance && pStats.canAttack()) { if (stats != null) { if (stats.AttackSpeed.CurValue <= 0) { playerCombat.Dot(stats.GetAttackDamage(), 0, 0); stats.AttackSpeed.CurValue = stats.AttackSpeed.FinalValue; } } FaceTarget(target); } } }