IEnumerator ThrowPokeball() { state = BattleState.Busy; if (isTrainerBattle) { yield return(dialogBox.TypeDialog($"You can't steal the trainers Pokemon!!!")); StartCoroutine(EnemyMove()); yield break; } yield return(dialogBox.TypeDialog($"{player.Name} used Pokeball!")); var pokeballObj = Instantiate(pokeballSprite, playerUnit.transform.position - new Vector3(2, 0), Quaternion.identity); var pokeball = pokeballObj.GetComponent <SpriteRenderer>(); // Animations yield return(pokeball.transform.DOJump(enemyUnit.transform.position + new Vector3(0, 2), 2f, 1, 1f).WaitForCompletion()); yield return(enemyUnit.PlayerCaptureAnimation()); yield return(pokeball.transform.DOMoveY(enemyUnit.transform.position.y - 1.9f, 0.5f).WaitForCompletion()); int shakeCount = TryToCatchPokemon(enemyUnit.Pokemon); for (int i = 0; i < Mathf.Min(shakeCount, 3); ++i) { yield return(new WaitForSeconds(0.5f)); yield return(pokeball.transform.DOPunchRotation(new Vector3(0, 0, 10f), 0.8f).WaitForCompletion()); } if (shakeCount == 4) { // Pokemon is caught yield return(dialogBox.TypeDialog($"{enemyUnit.Pokemon.Base.Name} was caught!")); yield return(pokeball.DOFade(0, 1.5f).WaitForCompletion()); playerParty.AddPokemon(enemyUnit.Pokemon); yield return(dialogBox.TypeDialog($"{enemyUnit.Pokemon.Base.Name} has been added to your party~")); Destroy(pokeball); BattleOver(true); } else { // Catch fail yield return(new WaitForSeconds(0.5f)); pokeball.DOFade(0, 0.2f); yield return(enemyUnit.PlayerBreakOutAnimation()); if (shakeCount < 2) { yield return(dialogBox.TypeDialog($"{enemyUnit.Pokemon.Base.Name} broke free!")); } else { yield return(dialogBox.TypeDialog($"Almost caught it!")); } Destroy(pokeball); StartCoroutine(EnemyMove()); } }
IEnumerator ThrowPokeball() { state = BattleState.Busy; if (isTrainerBattle) { yield return(dialogBox.TypeDialog($"You can't steal another trainer's pokemon!")); state = BattleState.RunningTurn; yield break; } yield return(dialogBox.TypeDialog($"Go Pokeball!!")); var pokeballObj = Instantiate(pokeballSprite, PlayerUnit.transform.position - new Vector3(2, 0), Quaternion.identity); var pokeball = pokeballObj.GetComponent <SpriteRenderer>(); yield return(pokeball.transform.DOJump(EnemyUnit.transform.position + new Vector3(0, 2), 2f, 1, 1f).WaitForCompletion()); yield return(EnemyUnit.PlayCaptureAnimation()); yield return(pokeball.transform.DOMoveY(EnemyUnit.transform.position.y - 1.3f, 0.5f).WaitForCompletion()); int shakeCount = TryToCatchPokemon(EnemyUnit.Pokemon); for (int i = 0; i < Mathf.Min(shakeCount, 3); i++) { yield return(new WaitForSeconds(0.5f)); yield return(pokeball.transform.DOPunchRotation(new Vector3(0, 0, 10f), 0.8f).WaitForCompletion()); } if (shakeCount == 4) { yield return(dialogBox.TypeDialog($"Gotcha! {EnemyUnit.Pokemon.Base.Name} was caught!")); yield return(pokeball.DOFade(0, 1.5f).WaitForCompletion()); playerParty.AddPokemon(EnemyUnit.Pokemon); yield return(dialogBox.TypeDialog($"{EnemyUnit.Pokemon.Base.Name} has been added to your party!")); Destroy(pokeball); BattleOver(true); } else { yield return(new WaitForSeconds(1f)); pokeball.DOFade(0, 0.2f); yield return(EnemyUnit.PlayBreakOutAnimation()); if (shakeCount == 0) { yield return(dialogBox.TypeDialog($"Oh no! The Pokemon broke free!")); } else if (shakeCount == 1) { yield return(dialogBox.TypeDialog($"Aww! It appeared to be caught!")); } else if (shakeCount == 2) { yield return(dialogBox.TypeDialog($"Aargh! Almost had it!")); } else if (shakeCount == 3) { yield return(dialogBox.TypeDialog($"Gah! It was so close too!")); } Destroy(pokeball); state = BattleState.RunningTurn; } }
//Coroutine to throw the ball IEnumerator ThrowPokeball() { state = BattleState.Busy; if (isTrainerBattle) { yield return(dialogBox.TypeDialog($"On ne vole pas les pokemon des autres dresseurs!")); //Display a message state = BattleState.RunningTurn; yield break; } yield return(dialogBox.TypeDialog($"{player.Name} lance une pokeball !")); var pokeballObject = Instantiate(pokeballSprite, playerUnit.transform.position - new Vector3(2, 0), Quaternion.identity); //This will "create" the pokeball, using the prefab var pokeball = pokeballObject.GetComponent <SpriteRenderer>(); //Grab a reference to the pokeball sprite //Animations yield return(pokeball.transform.DOJump(enemyUnit.transform.position + new Vector3(0, 2), 2f, 1, 1f).WaitForCompletion()); //DOJump will make it look like a jump. Vector2(0, 2) is ti get a bit above the target pos yield return(enemyUnit.PlayCaptureAnimation()); //Call the animation to make the pokemon go into the ball yield return(pokeball.transform.DOMoveY(-3.5f, 0.5f).WaitForCompletion()); //The ball fall on the ground int shakeCount = TryToCatchPokemon(enemyUnit.Pokemon); //Int to know how many times we need to shake for (int i = 0; i < Mathf.Min(shakeCount, 3); ++i) //Shake it "shakeCount" times, maximum 3 times { yield return(new WaitForSeconds(0.5f)); yield return(pokeball.transform.DOPunchRotation(new Vector3(0, 0, 10f), 0.8f).WaitForCompletion()); } if (shakeCount == 4) { //Pokemon is caught yield return(dialogBox.TypeDialog($"Vous avez attrapé un {enemyUnit.Pokemon.Base.name}!")); //Display a message yield return(pokeball.DOFade(0, 1.5f).WaitForCompletion()); //Fade out the ball playerParty.AddPokemon(enemyUnit.Pokemon); //Add the pokemon to the party yield return(dialogBox.TypeDialog($"{enemyUnit.Pokemon.Base.name} fait partie de votre équipe.")); //Display a message Destroy(pokeball); //Destroy the ball BattleOver(true); //End the battle } else { //Pokemon broke out yield return(new WaitForSeconds(1f)); pokeball.DOFade(0, 0.2f).WaitForCompletion(); //Destroy the ball yield return(enemyUnit.PlayBreakOutAnimation()); //Play the animation in reverse if (shakeCount < 2) //Show a dialog based on the shake count { yield return(dialogBox.TypeDialog($"{enemyUnit.Pokemon.Base.Name} s'est libéré..")); } else { yield return(dialogBox.TypeDialog($"Argh, c'était presque ça!")); } Destroy(pokeball); state = BattleState.RunningTurn; } }