Tutorial: an exploding barrel
A barrel that blows up when it is shot or hit hard. Everything nearby is pushed away and hurt and the camera shakes.
1. Set up

Make a Cylinder, give it a rigid body and a collider, and put the script on it.
2. The script

Scripts/Explosive.cs
public class Explosive : Behaviour
{
public float radius = 6f;
public float push = 12f;
public float damage = 60f;
bool gone;
public void TakeDamage(object amount) { Explode(); }
public override void OnCollisionEnter(GameObject other)
{
// something fast ran into it
if (other.rigidbody.exists && other.rigidbody.velocity.Length > 8f) Explode();
}
void Explode()
{
if (gone) return;
gone = true;
foreach (GameObject near in Physics.OverlapSphere(transform.position, radius, gameObject))
{
// nearer things are pushed harder and hurt more
Vector3 away = near.transform.position - transform.position;
float strength = 1f - Mathf.Clamp01(away.Length / radius);
if (near.rigidbody.exists) near.rigidbody.AddImpulse((away.Normalized + Vector3.up * 0.5f) * push * strength);
near.SendMessage("TakeDamage", damage * strength);
}
Camera.Shake(0.6f, 0.5f);
Audio.PlayAt("Audio/explosion.wav", transform.position, 1f, 1f, 60f);
GameObject.Destroy(gameObject);
}
}
Save it as Scripts/Explosive.cs.
3. How it works

- A bullet calls
barrel.SendMessage("TakeDamage", 50f); the barrel'sTakeDamageexplodes it. See health for that message. - A fast collision also explodes it:
OnCollisionEnterchecks the other object's speed. Physics.OverlapSpherelists everything withinradius. For each, the push and the damage fall off with distance: nearer things are hit harder.Camera.Shakeshakes the view;Audio.PlayAtplays a sound at the barrel's position (addAudio/explosion.wav).
4. Chain reactions

Put two barrels close together: the first one's blast calls TakeDamage on the second, which explodes too.
Next: waves of crates.