private void OnCollisionEnter2D(Collision2D other) { master.PlaySound("Hit"); if (other.gameObject.CompareTag("Zombie")) { ZombieStats zombie = other.gameObject.GetComponent <ZombieStats>(); zombie.TakeDamage(bulletDamage); if (!zombie.IsStartled()) { zombie.Startle(); } } else if (other.gameObject.CompareTag("Crate")) { Crate crate = other.gameObject.GetComponent <Crate>(); crate.Break(2); } Instantiate(hitParticle, transform.position, Quaternion.identity); Destroy(gameObject); }
void Attack() { if (Input.GetMouseButtonDown(0)) { if (isAttacking) { return; } Vector3 effOffset = new Vector2(player.facing == "L" ? -1 : 1, 0); GameObject eff = Instantiate(slashEffect, transform.position + effOffset, Quaternion.identity); eff.transform.localScale = new Vector2(player.facing == "L" ? -2 : 2, 2); Destroy(eff, 0.3f); knifeAnim.SetBool("isMeleeAttacking", true); Invoke("SetNotAttacking", 0.2f); isAttacking = true; Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position + (Vector3)(hitboxOffset * hitboxFacing), hitboxSize, 0f); foreach (Collider2D collider in colliders) { if (collider.gameObject.CompareTag("Zombie")) { ZombieStats zombie = collider.GetComponent <ZombieStats>(); zombie.TakeDamage(4); zombie.AddKnockback(transform.position, 100); } else if (collider.gameObject.CompareTag("Crate")) { Crate crate = collider.gameObject.GetComponent <Crate>(); crate.Break(4); } } } }