Hi, I need a simple raycast penetration system, which crosses certain walls to others. For example the wall labeled “penetrate” the bullet pierce and collide in another wall with normal tag
Overall, it tends to be most performant if you can use layers instead of tags, and only raycast for the layers you want to include. You do this via the layermask on the Raycast call. (Some of the overloads of Physics.Raycast support a layermask.)
If that’s not possible then you can use Physics.RaycastAll (or RaycastAllNonAlloc) to return all the hits. Sort them by hit.distance, and walk through them one at a time. For each collider you hit, you can test whether the collider’s gameObject’s CompareTag matches “penetrate”, and you can skip over that hit. As soon as you get a valid hit, you stop looping through the hits.