Here's a good solution, although it's slightly involved. Do your best to follow each step exactly.
- Create a new layer by clicking on Layers/Add Layer from any object. Name it "GunLayer".
- Put your gun on this layer by clicking Layers/GunLayer from the Layers dropdown while on the gun object.
- Create a new camera, and uncheck all the components except for the Camera component. Name it "Gun Camera"
- Then, still on the Gun Camera object, select the culling mask dropdown, and select GunLayer. This makes it so the camera will render only objects on the GunLayer layer.
- Set Clear Flags to Depth Only. This means it won't render a background or skybox or anything, just the gun.
- Move your Gun Camera object to the exact same coordinates as the main camera, and make it a child of the main camera. Getting it to the exact same coordinates is crucial.
That's it, your gun will no longer go through walls.
Apr 01 '11 at 07:59 PM