public void TakeDamage(int damage, HandleDamageColliders.DamageType damageType) { if (!gettingHit && !blocking) { switch (damageType) { case HandleDamageColliders.DamageType.light: StartCoroutine(CloseImmortality(0.3f)); break; case HandleDamageColliders.DamageType.heavy: handleMovement.AddVelocityOnCharacter( ((!lookRight) ? Vector3.right * -1 : Vector3.right), 0.5f ); StartCoroutine(CloseImmortality(1)); break; } health -= damage; gettingHit = true; //if(blood != null) //{ foreach (ParticleSystem ps in blood) { if (ps.gameObject.tag == "Hit") { ps.Emit(30); } } StartCoroutine(shake.Shake(.2f, .2f)); //} } if (blocking) { foreach (ParticleSystem ps in blood) { if (ps.gameObject.tag == "Block") { ps.Emit(30); } } } }
void OnTriggerStay2D(Collider2D col) { if (col.tag == "Enemy" && !invulerable && col.gameObject.GetComponent <Enemy_Destroy>().enabled&& health > 0) { invulerable = true; health--; hurt.Play(); if (health == 0) { StartCoroutine(death()); } health_sprites[health_sprite_index++].GetComponent <Animator>().SetBool("hurt", true); rb.AddForce(new Vector2(-(col.transform.position - transform.position).x * 2, 5), ForceMode2D.Impulse); StartCoroutine(c.Shake(4)); StartCoroutine(iframes(2)); } }