void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { HealthManager2.HurtPlayer(damageToGive); } }
void OnCollisionEnter2D(Collision2D coll) { if (coll.collider.tag == "Enemy") { HealthManager2.HurtPlayer(damageToGive); player.rb.AddForce(Vector3.left * 475); } }
IEnumerator MagicAttack() { GameObject Enemy = GameObject.FindWithTag("Enemy"); Animator magicOnEnemy = Enemy.transform.GetChild(0).gameObject.GetComponent <Animator>(); anim.SetBool("IsAttacking", true); yield return(new WaitForSeconds(0.3f)); source.PlayOneShot(magicSound, 1f); magicOnEnemy.SetBool("SpellActive", true); ShowDamage(attackPlayerSpellDamage); yield return(new WaitForSeconds(0.2f)); HealthManager2.HurtPlayer(attackPlayerSpellDamage); ManaBar1.HurtPlayer(attackPlayerSpellCost); Enemy.GetComponent <Animator>().SetBool("IsHurt", true); if (HealthManager2.enemyHealth <= 0) { yield return(new WaitForSeconds(0.3f)); HideDamage(attackPlayerSpellDamage); Enemy.GetComponent <Animator>().SetBool("IsHurt", false); Enemy.GetComponent <Animator>().SetBool("IsDead", true); movement = new Vector2(0, 0); magicOnEnemy.SetBool("SpellActive", false); } else { yield return(new WaitForSeconds(0.7f)); HideDamage(attackPlayerSpellDamage); anim.SetBool("IsAttacking", false); Enemy.GetComponent <Animator>().SetBool("IsHurt", false); yield return(new WaitForSeconds(0.3f)); magicOnEnemy.SetBool("SpellActive", false); yield return(new WaitForSeconds(0.5f)); scriptEnemy.turnEnemy = true; attacking = false; } }
IEnumerator OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy" && attacking) { if (!miss) { movement = new Vector2(0, 0); anim.SetBool("IsWalking", false); anim.SetBool("IsAttacking", true); ShowDamage(attackPlayerPhysDamage); yield return(new WaitForSeconds(1.1f)); source.PlayOneShot(swordSound, 1f); collision.gameObject.GetComponent <Animator>().SetBool("IsHurt", true); HealthManager2.HurtPlayer(attackPlayerPhysDamage); //WaitForAnimation(collision.gameObject.GetComponent<Animation>()); if (HealthManager2.enemyHealth <= 0) { yield return(new WaitForSeconds(0.3f)); HideDamage(attackPlayerPhysDamage); collision.gameObject.GetComponent <Animator>().SetBool("IsDead", true); } else { yield return(new WaitForSeconds(0.8f)); HideDamage(attackPlayerPhysDamage); anim.SetBool("IsAttacking", false); collision.gameObject.GetComponent <Animator>().SetBool("IsHurt", false); retire = true; } // rbody.MovePosition(rbody.position + new Vector2(0, 0)); } 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); // rbody.MovePosition(rbody.position + new Vector2(0, 0)); retire = true; miss = false; } } if (collision.gameObject.tag == "Wall") { retire = false; movement = new Vector2(0, 0); anim.SetBool("IsWalking", false); attacking = false; scriptEnemy.turnEnemy = true; } }