IEnumerator MagicAttack() { GameObject Hero = GameObject.FindWithTag("Hero"); Animator magicOnEnemy = Hero.transform.GetChild(0).gameObject.GetComponent <Animator>(); anim.SetBool("IsAttacking", true); source.PlayOneShot(magicSound, 1f); yield return(new WaitForSeconds(0.3f)); magicOnEnemy.SetBool("SpellActive", true); ShowDamage(attackEnemySpellDamage - InitializeValues.shieldValue); yield return(new WaitForSeconds(0.2f)); Hero.GetComponent <Animator>().SetBool("IsHurt", true); HealthManager1.HurtPlayer(attackEnemySpellDamage - InitializeValues.shieldValue); ManaBar2.HurtPlayer(attackEnemySpellCost); if (InitializeValues.lifePoints <= 0) { yield return(new WaitForSeconds(0.3f)); HideDamage(attackEnemySpellDamage - InitializeValues.shieldValue); Hero.GetComponent <Animator>().SetBool("IsHurt", false); Hero.GetComponent <Animator>().SetBool("IsDead", true); magicOnEnemy.SetBool("SpellActive", false); movement = new Vector2(0, 0); } else { yield return(new WaitForSeconds(0.7f)); HideDamage(attackEnemySpellDamage - InitializeValues.shieldValue); anim.SetBool("IsAttacking", false); Hero.GetComponent <Animator>().SetBool("IsHurt", false); yield return(new WaitForSeconds(0.3f)); magicOnEnemy.SetBool("SpellActive", false); yield return(new WaitForSeconds(0.5f)); scriptHero.turnHero = true; attacking = false; } }
IEnumerator OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Hero" && attacking) { if (!miss) { movement = new Vector2(0, 0); anim.SetBool("IsWalking", false); anim.SetBool("IsAttacking", true); ShowDamage(attackEnemyPhysDamage - InitializeValues.shieldValue); yield return(new WaitForSeconds(1.1f)); source.PlayOneShot(swordSound, 1f); collision.gameObject.GetComponent <Animator>().SetBool("IsHurt", true); HealthManager1.HurtPlayer(attackEnemyPhysDamage - InitializeValues.shieldValue); if (InitializeValues.lifePoints <= 0) { yield return(new WaitForSeconds(0.3f)); HideDamage(attackEnemyPhysDamage - InitializeValues.shieldValue); collision.gameObject.GetComponent <Animator>().SetBool("IsDead", true); } else { yield return(new WaitForSeconds(0.8f)); HideDamage(attackEnemyPhysDamage - InitializeValues.shieldValue); anim.SetBool("IsAttacking", false); collision.gameObject.GetComponent <Animator>().SetBool("IsHurt", false); retire = true; } } else { movement = new Vector2(((speed) / 3) * 2, 0); yield return(new WaitForSeconds(1.1f)); movement = new Vector2(0, 0); anim.SetBool("IsWalking", false); anim.SetBool("IsAttacking", true); yield return(new WaitForSeconds(1.1f)); source.PlayOneShot(swordSound, 1f); yield return(new WaitForSeconds(1.0f)); anim.SetBool("IsAttacking", false); retire = true; miss = false; } } if (collision.gameObject.tag == "Wall") { retire = false; movement = new Vector2(0, 0); anim.SetBool("IsWalking", false); attacking = false; scriptHero.turnHero = true; } }