Make gameObject always in front of another one

Guys,

I have 4 gameObjects that I use for the player control the Camera (left, up, right, down).

My problem is:

When one of these control buttons faces another gameObject in the scene, it gets behind of it, and I can’t click them. As in the example image.

[17895-error+example.png|17895]

I know, at least I think, this happens because the gameObject Z axis is lower than the button’s.

There is a way to solve this, just like a “send to front” option?

I’m hopeless. Thanks a lot for your help!

1 Answer

1

In a 3D game, this is usually accomplished by rendering multiple cameras: your main camera draws the scene, and then your second camera draws your UI over it.

This thread has some very handy reading, and you can also browse the Unity manual’s Camera page.

Long story short:

  • Put UI objects on their own layer
  • Put two cameras in the scene
  • Scene camera renders only scene-object layers
  • UI camera renders after, clears depth buffer, renders only UI-object layers

The main settings you’ll want to consider for each camera:

  • Depth: in which order do they render?
  • Clear flags: which render buffers do they clear?
  • Culling mask: which GameObject layers do they render?

Bear in mind that certain tasks (ie: raycasting to determine mouse/touch position) will be slightly more complicated.

Rutter, You really gave me a sign, I'll study this topics and try to figure out how to make them work in my project. Thanks for helping me again.

Rutter, I followed your tips and now my problem is solved. Thank you very much!

thanks really solve my problem