private IEnumerator CheckKingCondition() { if (!ManaCheck(1) || !King) { yield break; } float kingHealthThreshold = 0.75f; if (m_behaviour == BehaviourType.Aggressive) { kingHealthThreshold = 0.5f; } else if (m_behaviour == BehaviourType.Defensive) { kingHealthThreshold = 0.9f; } if ((float)King.GetCurrentHealth() / King.GetMaxHealth() < kingHealthThreshold) { List <Node> nearbyEnemyNodes = m_pathfinding.GetEnemyUnitNodesInRange(PlayerId, King.transform.position, false, 0, 10); if (nearbyEnemyNodes.Count > 0) { Unit closestEnemy = GetClosetEnemy(King.transform.position); print("AI moving king away from closest enemy " + closestEnemy.name); if (closestEnemy) { yield return(MoveUnitAway(King, closestEnemy)); } if (!ManaCheck(1)) { yield break; } // Bring closest ally to help Unit closestAlly = GetClosestAlly(King.transform.position); if (!closestAlly) { yield break; } if (closestAlly.unitType == Unit.UnitTypes.Priest) { if (CanHeal(closestAlly, King) && closestAlly.GetCanAttack()) { yield return(Heal(closestAlly, King)); } else { yield return(MoveUnitTowards(closestAlly, King.transform.position)); Debug.Log("AI moving " + closestAlly.name + " towards king to aheal"); } } else { Unit enemy = GetClosetEnemy(King.transform.position); if (!enemy) { yield break; } if (CanAttack(closestAlly, enemy) && closestAlly.GetCanAttack()) { yield return(Attack(closestAlly, enemy)); } else { yield return(MoveUnitTowards(closestAlly, King.transform.position)); Debug.Log("AI moving " + closestAlly.name + " towards king to attack nearby enemies"); } } } } }