In my turn based game, I like to have a function similar to Unity's [WaitForSeconds][1], [WaitUntil][2] that can be called within a IEnumerator that suspends the coroutine execution for the given amount of moves. I already have a public working UnityEvent (moveEvent) which I could listen to.


So I could call it from any IEnumerator like:

 IEnumerator Example()
 {
 yield return new WaitForMoves(2);
 }

I think I'd need a separate class like:

 class WaitForMoves {
 
 int moves = 0;
 
 void Start() {
 Game.moveEvent.AddListener(OnMoveComplete);
 }
 
 void OnMoveComplete() {
 moves++;
 }
 
 // I'm not sure how to write this in a way that it waits
 // until this.moves === movesToWait
 public WaitForMoves(int movesToWait) {
 
 }
 }


 [1]: https://docs.unity3d.com/ScriptReference/WaitUntil.html
 [2]: https://docs.unity3d.com/ScriptReference/WaitForSeconds.html