0

I am creating my first 3D game, it including a HP bar will always show on the screen with FPS camera.

My HP bar is an image and the background of this game is a 3D house. The problem is that my HP bar will penetrate the wall of house sometimes.

I have tried some solution such like using sorting layers, setting HP bar as higher layers in sorting layer and setting the 3D house as lower layer, but it doesn't work.what's the problem here?

shilovk
  • 11,718
  • 17
  • 75
  • 74
Licccc
  • 3
  • 4

2 Answers2

1

For HUD, you should use unity UI components and make sure the canvas is set to Screen Space Overlay, you dont have to use layers as this will always be displayed in front of the camera. https://docs.unity3d.com/Manual/class-Canvas.html

comphonia
  • 521
  • 3
  • 10
1

You can use screen space overlay to fix your problem.Screen space overlay render mode will enable your UI elements to be always render in front of the 2d or 3d objects present in the scene.Hope this fixes your problem.