diff --git a/Assets/Scripts/Weapons/Grenade.cs b/Assets/Scripts/Weapons/Grenade.cs index d28b370..aef86c5 100644 --- a/Assets/Scripts/Weapons/Grenade.cs +++ b/Assets/Scripts/Weapons/Grenade.cs @@ -32,16 +32,23 @@ public class Grenade : MonoBehaviour GameObject spawnedExplosion = Instantiate(explodeParticle, transform.position, transform.rotation); // Destroys explosion particle after on second Destroy(spawnedExplosion, 1); + // Gets all collider that are in a sphere around the grenade Collider[] colliders = Physics.OverlapSphere(transform.position, weapon.GrenadeRadius); // Iterate over all colliders found in radius foreach(Collider nearbyObject in colliders) { - // Get Rigidbody from nearby object and... - Rigidbody rb = nearbyObject.GetComponent(); - // if rigidbody exists... - if(rb != null) { - // adds force to nearby objects - rb.AddExplosionForce(weapon.ExplosionForce, transform.position, weapon.GrenadeRadius); + // Check if nearby object is a Player + if (nearbyObject.transform.gameObject.GetComponent()) { + // Remove health from player + nearbyObject.transform.gameObject.GetComponent().RemoveHealth(weapon.Damage); + } else { + // Get Rigidbody from nearby object and... + Rigidbody rb = nearbyObject.GetComponent(); + // if rigidbody exists... + if (rb != null) { + // adds force to nearby objects + rb.AddExplosionForce(weapon.ExplosionForce, transform.position, weapon.GrenadeRadius); + } } } weapon.HasExploded = true;