Restrict colliding by something

For example:
There is enemy which can be hit by a bullet,
so there is collider for that.
Now I need another collider for click ray casting in order to selecting/targeting enemy(target enemy).
(these colliders are in same place but select/target is larger (sphere colliders))
Logically there is a script (for bullet)

 private void OnTriggerEnter(Collider col)
 {
        Enemy enemy = col.gameObject.GetComponent<Enemy>();
        if(enemy!=null)
        {
            enemy.Health -= 1f;          
            Destroy(this.gameObject);
        }
        
 }

but if there is 1000 enemies
that means that it will check 1000 collisions for select(which do not mean anything to bullet)
and 1000 for enemy

So is there way to restrict these colliding by something(tag,layer…?)?
Or some other way is appreciated.

I think the best thing to do here is to use specific layer for your selection collider. In order to do that, the bigger collider needs to be on a different gameObject than the smaller one for collision. So just add a new gameObject, put your bigger collider on it, then set the parent of this new gameObject to that of the smaller colliders gameObject.


Then, create a new layer named “Selection” or whatever you want and assign it to the bigger colliders gameObject. I would then go into edit → Settings → Physics and remove all the relationships with selection. Meaning, you don’t want enemies to collide with Selection layers.


Lastly, when you do the raycast, do it with a layermask with “Selection” layer. This means the ray will only hit colliders with layer of “Selection”


Hope this gets you in a decent direction.