public void Update() { if (Target == null) { return; } var dist = Vector3.Distance(Target.transform.position, this.transform.position); switch (state) { case AttackerState.Attacking: var dir = Target.transform.position - this.transform.position; if (dist >= attackRange) { self.Move(dir.normalized); } else if (dist < attackRange) { if (CO_Attack == null && Target.CurrentHealth > 0) { CO_Attack = StartCoroutine(DealDamageRoutine()); } else if (Target.CurrentHealth <= 0) { Target = null; } } else if (dist > detectionRange) { StopCoroutine(CO_Attack); state = AttackerState.Searching; } break; case AttackerState.Searching: if (dist <= detectionRange) { state = AttackerState.Attacking; } break; } }