private void OnTriggerEvent(Weapon weapon) { if (particleSystem != null) { particleSystem.Play(); } RaycastHit hit; if (Physics.Raycast(transform.position, transform.rotation.eulerAngles, out hit, _range)) { GameObject victim = hit.collider.gameObject; Hurtable hurtable = victim.GetComponent <Hurtable>(); if (hurtable != null) { hurtable.Damaged(this.damage, this.gameObject, this); Hitted((victim)); } } }
/// <summary> /// Lets the granade exlode /// </summary> void Explode() { GameObject explosion = Instantiate(explosionEffect, transform.position, transform.rotation); Destroy(explosion, 3f); Collider[] coliders = Physics.OverlapSphere(transform.position, radius); foreach (var colider in coliders) { Hurtable h = colider.GetComponent <Hurtable>(); Rigidbody rb = colider.GetComponent <Rigidbody>(); if (h != null) { h.Damaged(this.damage, this.parentWeapon.parent, this.parentWeapon); } if (rb != null) { rb.AddExplosionForce(explosionForce, transform.position, radius); } } Destroy(this.gameObject); }