How to Destroy gameObjects and deal damage within a radius except player ?


Ive been wondering how to I achieve a destruction radius that also does damage to other gameobjects except my player.
In short my player is launching a missile, after a few secconds that missile explodes , and when it explodes i want it to destroy all gameobjects within a radius or deal damage to them except the player.

I`ve been looking at the Physics.OverlapSphere but i cant get my way to work it.

thanks guys.

Physics.OverlapSphere is a good way to go. You will be doing almost exactly what the example script is doing although I would suggest that instead of using SendMessage you call an actual function. [Example script][1]

So I will break down the general idea. You get a set of colliders that are in range, then you loop through them and if it is an object that you can hit you apply the damage or just destroy them.

This gives you a list of colliders

Collider[] hitColliders = Physics.OverlapSphere(center, radius);

This loops through them

for(int i=0; i<hitColliders.Length; i++){

This checks if it is an object you want (using tags, but you could do this other ways)

if(hitColliders*.gameObject.tag == "Enemy"){*

This calls a function on the object
EnemyBaseClass enemy = (EnemyBaseClass)hitColliders*;*
if(enemy != null){
If you want more specific help then that you will have to post your code so we can see where you are going wrong.

I resolved it on my own, i just instantiated an empty game object with a sphere colliders that does the job upon rocket death.

Thanks for the help!