public IEnumerator DoLogic() { while (!damageable.IsDead) { Vector2 moveTowards = Vector2.zero; float chargeTime = 0.0f; using (DamageListener damageListener = new DamageListener(damageable, (source, damageable) => { moveTowards = -source.Direction; movement.TargetVelocity = moveTowards * chargeSpeed; Vector2 position = transform.position; chargeTime = Vector2.Dot(moveTowards, source.DamagePosition - position) / chargeSpeed; return(source); }, false)) { AsyncManager patrol = new AsyncManager(Patrol.PatrolForever(movement, patrolParameters)); while (patrol.Next()) { yield return(null); if (sight.GetVisibleObject() != null || externalTarget != null) { break; } if (chargeTime > 0.0f) { patrol = new AsyncManager(AsyncUtil.Pause(chargeTime)); chargeTime = 0.0f; } } } GameObject target = null; if (externalTarget) { target = externalTarget; externalTarget = null; } Collider2D sightTest = sight.GetVisibleObject(); if (sightTest != null) { target = sightTest.gameObject; AlertNearbyZombies(target); } while (target != null && sight.canSeeObject(target)) { Vector2 offset = target.transform.position - transform.position; movement.TargetVelocity = offset.normalized * chargeSpeed; yield return(null); } movement.TargetVelocity = Vector2.zero; yield return(new WaitForSeconds(1.0f)); } }