Here is the Unity3D answer.
http://answers.unity3d.com/questions/39420/gun-goes-through-wall-in-a-fps.html
Unity puts the weapon on a separate layer and uses depth on the camera(sometimes, they use multiple cameras), so that it doesn’t go through walls.
Hopes this helps.