IEnumerator EndTurn() { Card ourMove = null; if (selectedCardMove != null) { ourMove = selectedCardMove.card; } Card ourAction = null; if (selectedCard != null) { ourAction = selectedCard.card; } //Play our move card, if we chose one if (ourMove != null) { UIManager.instance.SpawnIndicatorCard(ourMove, true, false); } //Choose enemy move Card enemyCardMove = enemy.AIChooseCard(CardType.Move); if (enemyCardMove != null) { UIManager.instance.SpawnIndicatorCard(enemyCardMove, false, false); } //Choose and show enemy action Card enemyCard = enemy.AIChooseCard(CardType.Normal); if (enemyCard != null) { UIManager.instance.SpawnIndicatorCard(enemyCard, false, true); } //Show our action if (ourAction != null) { UIManager.instance.SpawnIndicatorCard(ourAction, true, true); } player.deck.DiscardHand(); enemy.deck.DiscardHand(); //give some time yield return(new WaitForSeconds(0.5f)); if (enemyCardMove != null) { enemyCardMove.onPlay(enemyCardMove); } if (ourMove != null) { ourMove.onPlay(ourMove); } //wait for both move animations to finish while (player.animationPlaying || enemy.animationPlaying) { yield return(new WaitForSeconds(0.1f)); } //bumps if (player.position == enemy.position) { player.Bump(); enemy.Bump(); if (player.facingRight != enemy.facingRight) { Debug.Log("NOrmal bump"); player.Move(-1); enemy.Move(-1); } else { if (Random.Range(0, 2) == 1) { player.SetFacingRight(true); enemy.SetFacingRight(false); player.Move(-1); enemy.Move(-1); } else { player.SetFacingRight(false); enemy.SetFacingRight(true); player.Move(-1); enemy.Move(-1); } } } //wait for both move animations to finish while (player.animationPlaying || enemy.animationPlaying) { yield return(new WaitForSeconds(0.1f)); } //give some time yield return(new WaitForSeconds(0.5f)); //handle priorities if (ourAction != null && enemyCard != null) { if (ourAction.priority > enemyCard.priority) { Debug.Log("Our Priority"); ourAction.onPlay(ourAction); while (player.animationPlaying || enemy.animationPlaying) { yield return(new WaitForSeconds(0.1f)); } enemyCard.onPlay(enemyCard); } else if (enemyCard.priority > ourAction.priority) { Debug.Log("Their Priority"); enemyCard.onPlay(enemyCard); while (player.animationPlaying || enemy.animationPlaying) { yield return(new WaitForSeconds(0.1f)); } ourAction.onPlay(ourAction); } else { Debug.Log("No Priority"); ourAction.onPlay(ourAction); enemyCard.onPlay(enemyCard); } } else { if (ourAction != null) { ourAction.onPlay(ourAction); } if (enemyCard != null) { enemyCard.onPlay(enemyCard); } } //verify if card was in hand? //wait for both move animations to finish while (player.animationPlaying || enemy.animationPlaying) { yield return(new WaitForSeconds(0.1f)); } selectedCard = null; selectedCardMove = null; StartTurn(); }