- Home /
Render real world UI infront of only 1 other Layer
Hello, I was wondering if there was a way to render a real world UI item in front of only one other single layer. I know you can render it in front of everything using multiple cameras, or by a custom shader ignoring z. I have a health bar that I want to stay behind everything, but my character which is on a separate layer. I imagine it would be making a custom shader but I'm not very familiar with them. Any help would be great thanks!
Answer by Harinezumi · Jan 29, 2018 at 06:33 AM
Hello,
this can be solved in various ways, possibly the easiest is to set the Canvas Render mode to World space. This way your UI will be actually part of the 3D environment, so objects can cover it from view. You will also need a script that anchors the UI to the position of the player and moves it slightly towards the camera (for example by -camera.transform.forward
).
Another solution is to use multiple cameras and layers, and render the background first, then the player and the UI, and finally the environment that can cover it, using Depth only for the culling mask and higher Depth value for each "layer" drawn.
Your answer
Follow this Question
Related Questions
UI mask does not work on children with different Canvas component and particles 0 Answers
Image effect shader that masks spritelayer 1 Answer
Display a world-space canvas to overlay all the meshes but not the other UI objects 0 Answers
Objects not drawn with custom vertex/fragment shader when in any other layer than the default layer 1 Answer
Camera layering : UI shader is cleared by second camera with Depth Only flag 1 Answer