I'm creating a card game, and I have run into an issue of 'pausing' my code while I wait for a player to make a decision in-game. As a background, I create a list of all the plays for the turn, and they are stored (and sent to opponent) with six pieces of information -- who's playing it, the card itself (so I know what the card does), the location of the play (hand/field/etc), the position in that location (card #1 in hand, etc), as well as where it's being played and that position. This is all saved in a list, and I evaluate the list when until it's empty.
So for example: (true, card1, Hand, 1, Field, 1) (true, card2, Hand, 2, Field, 2) (false, card1, Hand, 1, Field, 3)
Would play the first card in my hand to first field position, then second card in my hand to field position, and finally the first card in an opponent's hand to position #3.
This works great if I know all plays ahead of time -- I just have a laundry list of what to do and I evaluate through it, no problem.
BUT I'd like to add in the ability to have responsive effects -- say for example, I have a card that when it dies I can deal 3 damage to target unit. I'd need to 'interrupt' the flow on both my client and the opponent's client when we reach this point until the controlling player makes his decision on who'd he'd target, send it to the opponent, and then we can both proceed. As sample code, here's what I currently do
This will play out every card in the stack array (it has a script component that stores all relevant information) one at a time. EvalCard snippet looks like this:
What I would like to do is something like this:
But this will freeze unity due to the while loop without 'foreseeable' end. So, is there any way to feasibly make that function work?