/// Main control func public IEnumerator control(bool isTrainerBattle, Trainer trainer, bool healedOnDefeat) { // Set this up later int[] initialLevels = new int[6]; trainerBattle = isTrainerBattle; Pokemon[] opponentParty = trainer.GetParty(); string opponentName = trainer.GetName(); // Get battle backgrounds // ... victor = -1; // Reset position variables // ... setSelectedTask(-1); bool running = true; bool runState = true; // Set active Pokemon setEnemyActivePokemon(opponentParty[0]); setPlayerActivePokemon(playerParty[0]); setUpPokemonButtons(); // Set Pokemon sprites opponentBase.transform.FindChild("Pokemon").GetComponent <Image>().sprite = enemyActivePokemon.GetFrontSprite(); playerBase.transform.FindChild("Pokemon").GetComponent <Image>().sprite = playerActivePokemon.GetBackSprite(); if (trainerBattle) { } else { StartCoroutine(BattleScreenFade.main.FadeCutout(1.5f)); StartCoroutine(slidePokemon(opponentBase, false, new Vector2(87, 16))); yield return(StartCoroutine(slidePokemon(playerBase, true, new Vector2(-84, -58)))); Dialog.DrawDialogBox(); StartCoroutine(Dialog.DrawTextSilent("A wild " + enemyActivePokemon.getName() + " appeared!")); yield return(new WaitForSeconds(1.0f)); Dialog.UndrawDialogBox(); } setSelectedTask(0); while (running) { runState = true; while (runState) { Debug.Log(taskSelected); if (taskSelected == 0) { OptionBox.SetActive(true); PokemonSelectionBox.SetActive(false); } else if (taskSelected == 4) { if (trainerBattle) { OptionBox.SetActive(false); Dialog.DrawDialogBox(); yield return(StartCoroutine(Dialog.DrawTextSilent("No! There's no running from a trainer battle!"))); yield return(new WaitForSeconds(1.0f)); Dialog.UndrawDialogBox(); OptionBox.SetActive(true); setSelectedTask(0); } else { OptionBox.SetActive(false); Dialog.DrawDialogBox(); yield return(StartCoroutine(Dialog.DrawTextSilent("Got away safely!"))); yield return(new WaitForSeconds(1.0f)); Dialog.UndrawDialogBox(); setSelectedTask(-1); runState = false; running = false; } } else if (taskSelected == 2) { OptionBox.SetActive(false); PokemonSelectionBox.SetActive(true); while (taskSelected == 2 && pokemonSelected < 0) { Debug.Log("waiting.."); yield return(new WaitForSeconds(0.2f)); } if (pokemonSelected >= 0) { yield return(StartCoroutine(switchPokemonOut(true, false, false))); yield return(StartCoroutine(switchPokemonIn(true, pokemonSelected))); setSelectedTask(0); } } yield return(null); } } // yield return null; this.gameObject.SetActive(false); }