private IEnumerator EnemyLogic() { void ExecuteAllCustomScripts() { customMechanicScripts.ForEach(customMechanicScript => customMechanicScript.PerformCustomMechanic(this)); } while (_currentHealth > 0) { if (priorities.alwaysUseCustomMechanic) { ExecuteAllCustomScripts(); } var action = GetAction(); switch (action) { case EnemyPriorityEnum.Attack: if (attackScript != null) { attackScript.PerformAttack(); } else { PerformSimpleAttack(); } break; case EnemyPriorityEnum.Defend: if (_hasShield) { shieldBehavior.gameObject.SetActive(true); shieldBehavior.TurnShieldOn(); } break; case EnemyPriorityEnum.Moving: var position = transform.position; _internalCurvePosition += movementIntensity; var newPosition = _movementDirection * movementCurve.Evaluate(_internalCurvePosition); var moveTo = new Vector3(position.x + newPosition, position.y - movementOnY); moveTo.x = Mathf.Clamp(moveTo.x, _minPosition.x, _maxPosition.x); _internalTween = transform.DOMove(moveTo, actTimer).OnComplete(() => { if (transform.position.y < GameLogic.GetInstance().Level.LimitY) { Removal(); } }); break; case EnemyPriorityEnum.Waiting: // Does nothing break; case EnemyPriorityEnum.Custom: if (!priorities.alwaysUseCustomMechanic) { ExecuteAllCustomScripts(); } break; default: throw new ArgumentOutOfRangeException(); } yield return(new WaitForSeconds(actTimer)); } }