private IEnumerator AttackEnemy() { //attack! damage = (playerAttack + UnityEngine.Random.Range(-1, 1)) - enemyArmor; info.text = ("You deal " + damage + " damage!"); enemyHp -= damage; //checking if gum monster dead if (enemyHp <= 0) { enemyHp = 0; yield return(new WaitForSeconds(2)); info.text = ("You won the battle!"); begone.Dissappear(); //audioSource.PlayOneShot(victoryJingle, 1F); yield return(new WaitForSeconds(2)); info.text = ("You got a chewed gum!"); yield return(new WaitForSeconds(2)); infoWin.DeActivate(); initWin.Activate(); //say player won victory = true; PlayerPrefs.SetInt("whereX", xPos); PlayerPrefs.SetInt("whereY", yPos); Flee(); //SceneManager.LoadScene("Overworld"); } else { //monster alive still yield return(new WaitForSeconds(2)); //monster attack back damage = (enemyAttack + UnityEngine.Random.Range(-1, 1)) - playerArmor; info.text = ("The gum attacks you for " + damage + " damage!"); playerHp -= damage; if (playerHp <= 0) { playerHp = 0; yield return(new WaitForSeconds(2)); info.text = ("You have lost to the gum..."); yield return(new WaitForSeconds(2)); infoWin.DeActivate(); initWin.Activate(); SceneManager.LoadScene("GameOverScreen"); } yield return(new WaitForSeconds(2)); //back to initial window infoWin.DeActivate(); initWin.Activate(); } }
private IEnumerator AttackEnemy() { //attack! damage = (playerAttack + UnityEngine.Random.Range(-1, 1)) - enemyArmor; info.text = ("You deal " + damage + " damage!"); enemyHp -= damage; //checking if gum monster dead if (enemyHp <= 0) { enemyHp = 0; yield return(new WaitForSeconds(2)); info.text = ("You won the battle!"); begone.Dissappear(); yield return(new WaitForSeconds(2)); info.text = ("You got a chewed gum!"); yield return(new WaitForSeconds(2)); Victory(); } else { //monster alive still yield return(new WaitForSeconds(2)); //monster attack back damage = (enemyAttack + UnityEngine.Random.Range(-1, 1)) - playerArmor; info.text = ("The gum attacks you for " + damage + " damage!"); playerHp -= damage; if (playerHp <= 0) { playerHp = 0; yield return(new WaitForSeconds(2)); info.text = ("You have lost to the gum..."); yield return(new WaitForSeconds(2)); infoWin.DeActivate(); initWin.Activate(); SceneManager.LoadScene("GameOverScreen"); } //back to initial window yield return(new WaitForSeconds(2)); infoWin.DeActivate(); initWin.Activate(); } }