I am attempting to make my first FPS game in unity and have been just making mechanics for now. One of which involves adding a sniper that can scope which required the weapon to be rendered separately from the rest of the game so the scope overlay comes up when aiming in and you can no longer see the gun model as it would get in the way otherwise. This was done in the tutorial I followed by having a separate camera rendering just the held weapon.
This all works perfectly, the problem occurs due to the fact that my game also has weapon dropping and picking up (also works perfectly) which makes it so I want the weapon rendering separately to work when guns picked up off the ground are scoped in so I made it so all weapons are part of the weapons layer which is rendered by the weapons camera. This creates the problem that guns on the ground that can be picked up now render on top of everything due to the weapon camera. To change this I attempted to change the layers of the weapons in runtime to make it so only the held weapon is rendered by the weapon camera but this does not work. Is there any way to get around this problem so the player-held weapon is rendered separately from everything else and this changes when weapons are dropped and picked up?