'Last IEnumerator in sequence not triggering
I have an IEnumerator that yield-returns to several others in sequence:
IEnumerator AttackSequence(HexCell target)
{
yield return LookAt(target.Position);
yield return RangedPhase(target);
yield return AssaultPhase(target);
yield return MeleePhase(target);
yield return Overtake(target, true);
}
All up through MeleePhase run correctly, performing the steps of two units fighting each other. Overtake then performs cleanup of defeated units, and should handle a victorious attacker entering the loser's space:
IEnumerator Overtake (HexCell target, bool advance)
{
if (target.Unit.curSize <= 0)
{
if (curSize <= 0)
{
Debug.Log("Defeated (barely)");
target.Unit.curSize = 1;
Grid.RemoveUnit(this);
}
else
{
Grid.RemoveUnit(target.Unit);
Debug.Log("Victorious!");
if (advance)
{
pathToTravel = new List<HexCell>();
pathToTravel.Add(location);
pathToTravel.Add(target);
Debug.Log("Overrunning!");
yield return TravelPath();
}
}
}
else if (curSize <= 0)
{
Debug.Log("Defeated");
Grid.RemoveUnit(this);
}
yield return null;
}
Everything in Overtake works correctly (defeated units do get removed), except it doesn't seem to yield to TravelPath correctly. I get the debug message from the previous line, but no indication that TravelPath actually got called. (Its first line currently contains a debug message that I DON'T get, and the unit doesn't actually move.)
TravelPath works correctly when started in other circumstances. I've also tried moving the "yield return TravelPath()" into the AttackSequence() while debugging, and it doesn't go off that way, either. Surely there's not a cap on how many yield-returns can be used in an IEnumerator?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
