checking colliders from multiple raycast

Trying to raycast within a layerMask and check which colliders were hit, which were not, by checking them in a for loop

aArrayOfColliders is obtained at Start()

Ray ray = //basically a group of rays

   if (Physics.Raycast (ray, hit, Mathf.Infinity,1<<4)){
    	for(var hit in aArrayOfColliders){
    	//do stuff
        for (var !hit in aArrayOfColliders){
        //do something else

Fire as many rays as you like, they will still hit the first object.

Try RaycastAll

If you wish to be selective with your RayCasts, employ a LayerMask.

To find what’s NOT hit:

You would need to collect all the objects’ information in the layer.

Check the Physics page in the Scripting Reference.

OverlapSphere will return all colliders within a radius from a point.

SphereCastAll is just like RayCastAll but is a thick beam.

Use OverLap to find ALL colliders, or, use SphereCastAll to find all colliders in the fat beam in a direction, then use RayCastAll to fire a smaller beam for the hit. Mix these up and you should have two separate arrays. One with all objects and one with objects hit.

And Here is an awesome QA on using LayerMasks. Read and absorb. It’s totally worth it.