How is OverlapSphere used?

I've only found a few posts about it, but i haven't seen it USED, only declared in a var. var EG `colliders = Physics.OverlapSphere( position, 150.0);`

So how exactly do you put this to use?

This was posted by "Duck" a while back: Click Here

*If your enemies have colliders attached, you can use Physics.OverlapSphere to quickly get your initial list of enemies within a certain radius.

You can then loop through each enemy within this list and determine the relative distance to the player, and apply some level of damage to each enemy within the radius, proportional to its distance.

It would end up looking something like this. It assumes that your enemy objects have both a collider and a script called "Enemy" attached.*

function AreaDamageEnemies(location : Vector3, radius : float , damage : float )
    var objectsInRange : Collider[] = Physics.OverlapSphere(location, radius);
    for (var col : Collider in objectsInRange)
        var enemy : Enemy = col.GetComponent(Enemy);
        if (enemy != null)
            // linear falloff of effect
            var proximity : float = (location - enemy.transform.position).magnitude;
            var effect : float = 1 - (proximity / radius);

            enemy.ApplyDamage(damage * effect);

The potential uses, like for most everything in the Unity API, are infinite.

Let's see what comes off the top of my subconscious...

An enzyme is in a stomach. Check to see if certain proteins are within range of the enzyme. Destroy the colliders for the proteins that overlapped because now they're more gooey and ephemeral, instead of being solid gelatinous globs.

That ship from The Abyss starts rising at the end of the movie. Check the sphere around it, and if any dolphins are within range, have them freak the @$#% out. As in, maybe use Collider.attachedRigidbody along with Rigidbody.AddExplosionForce.

Like the docs say, it's dealing with bounding boxes, so it could result in more useful behavior sometimes, than just checking distances between transform.positions, as distance checks often do.