// A attack, D defend, H health IEnumerator TurnRoutine() { while (true) { // Player gets first turn if (isPlayer && isAttacking) { Debug.Log("Player attacking"); if (Input.GetKey(KeyCode.A)) { //TODO: do attack animation if (!otherFighter.Defending) { otherHealth.decreaseHealth(attackPower); } otherFighter.Defending = false; if (otherHealth.IsDead()) { GameManager.S.ShowGameOver(); break; } isAttacking = false; otherFighter.Attacking = true; } else if (Input.GetKey(KeyCode.D)) { //TODO: do defense animation myHealth.ActivateDefense(true); isAttacking = false; otherFighter.Attacking = true; } else if (Input.GetKey(KeyCode.H)) { //TODO: do health animation myHealth.IncreaseHealth(recoverPower); isAttacking = false; otherFighter.Attacking = true; } else { yield return(null); continue; } // AI is attacking } else if (isAttacking) { Debug.Log("AI Attacking"); int rand = Random.Range(1, 3); switch (rand) { //TODO: add the animations case 1: if (!otherFighter.Defending) { otherHealth.decreaseHealth(attackPower); } otherFighter.Defending = false; break; case 2: myHealth.ActivateDefense(true); break; default: myHealth.IncreaseHealth(recoverPower); break; } if (otherHealth.IsDead()) { GameManager.S.ShowGameOver(); break; } isAttacking = false; otherFighter.Attacking = true; } else { Debug.Log("Waiting"); //Wait until other fighter does something yield return(new WaitUntil(() => isAttacking == true)); } yield return(null); } }