how do i tell if a object with a diffrent layer then mine comes within range

I’m making soldiers that are on certain teams and i need them to automatically shoot at a object if it has a different layer than itself and if its in range to tell me that he is ready to shoot.

I dont want you to make the shooting part of the script i just need if the layer is not the same as mine and it is in range to Debug.log(“somthing”);

You can use Physics.OverlapSphere. It will, given a position, a radius, and a layermask, return all the colliders within the give range from the position, as long as their layers match the layermask. In your case the layermask would be all the layers except your own (or just get all the layers and then when iterating, skip your own):

int allLayersExceptMine = ~(1 << gameObject.layer);
Collider[] colliders = Physics.OverlapSphere(transform.position, range, allLayersExceptMine );

foreach (Collider other in colliders) {
    Debug.Log("Shooting at " +;