Find nearest object

I’m drawing a blank here. I know this is possible and I’m almost sure I’ve done something like this, but I can’t recall what any of the commands are, so I can’t even search the documentation for this.

How can I find the nearest object with a particular script attached to it?

FindGameObjectsWithTag has an example of finding the closest enemy. It wouldn’t really make sense searching for a script, I don’t think.

Often its easier to maintain a list of all of the instances of the script you need, then search that.

Alternatively you can use FindObjectsOfType, but its slow.