I have searched for hours and tried many different things to get this to work, but no luck.
I have a 2d-mesh which defines the shape of a Level, sitting on the layer “LevelMask”.
Then I got many different 2d-Objects, like the Player, that should only render on top of the level when they are inside the LevelMask/the shape of the level. As soon as they are outside of the level, they should not render. These LevelObjects sit in a layer called “LevelObjects”.
I tried this approach with two cameras. In the camera-preview everything looks like it should look, the level camera only shows the level, and the levelObjects camera only shows the levelObjects. Both cameras move simultaneously and are always in the same position/shape/rotation.
Ingame however the level either doesn’t mask the objects while the level itself turns transparent, or the Rendertexture only updates on first frame, coloring the whole level into what the first frame has shown, without the levelObjects being visible at all.
I have tried changing the Depth of my two cameras, changing the culling masks, changing the clear flags, switching the target texture and a lot more with no success.
Any ideas on how I can easily use my LevelMask layer/my levelMask-Camera to mask everything within the LevelObjects layer? What might have gone wrong here? I am utterly frustrated, that such a simple thing seems not to be working. Thanks.