How to make UI elements behind game objects without using World Space Canavas
Hey everyone, I'm trying to make a Pong clone to learn Unity. And I wanted to display the score in the middle of the screen, I did it but now the ball is rendering behind the text that displays the score. I want to render the text before the ball, and then show the ball over it. If I change the canvas to world size, it won't resize with the screen.
I tried making the ball a child of another separate cavas and changing the "Sort order" parameter of the ball's canvas, but apparently, that parameters only affects UI elements. And moving the ball inside the text's canvas in putting it below and over the text but it won't work either.
Placing the ball over and below the text in the hierarchy window but it doesn't do anything. And changing the text's layer doesn't seem to work, as well as changing the canvas' layer.
I thought about changing the ball's parameter Order in Layer, in the Sprite Render. But text isn't affected by that, I guees that it is because it doesn't have a Sprite Renderer. Same goes for creating a new Sorting Layer and adding the ball to it. In a desperate attempt I added a Sprite Render to the text but as expected, didn't do anything.
I just thought about making a second camera that renders only the UI and making it to render before the main camera. But UI doesn't care about cameras, even if you disable all cameras, it keeps rendering.
I would go with that later solution.
Just set your Canvas to Camera Space
instead of Overlay
Your answer
Follow this Question
Related Questions
Weird artefacts (black spots) in Camera Space UI elements 1 Answer
How can I raycast gameobjects with specific layer ? 1 Answer
Ignore Raycast not working properly? 0 Answers
Set a (foreground) UI layer which ignores mouse clicks? 0 Answers
UI Text sometimes renders when instantiated, yet sometimes does not. 1 Answer