protected virtual void Work() { FindTarget(); if (_target != null) { LookAtEnemy(); if ((gameObject.transform.position - Target.transform.position).sqrMagnitude <= Mathf.Pow(MINDistToAttack, 2)) { _targetHP = _target.GetComponent <HealthPoints>(); _rb.velocity = Vector3.zero; if (_animator.GetInteger(_attackAnimationName) == 0) { Attack(); } _animator.speed = 2 / attackDelay; } else { _animator.SetInteger(_attackAnimationName, 0); Vector3 movementDirection = (Target.transform.position - transform.position).normalized; _rb.velocity = movementDirection * speed; } } else { if (UnitSide == UnitSide.PLAYER) { _uiMethods.Win(); } _rb.velocity = Vector3.zero; _animator.SetInteger(_attackAnimationName, 0); } }