- Home /
3d Object in GUI Layer
Is it possible to put a 3D Object on the GUI Layer?
I made a life bar out of 3D heart shapes. I scripted them and added them as a GameObject. Then I parented the heart GameObjects to the mainCamera. It works fine but there are some flaws with this approach. I have to manually position the hearts for each scene.
Is it possible to put the heart GameObjects on the GUI Layer instead? It would be a simpler approach.
Answer by flaminghairball · Jun 07, 2011 at 02:06 PM
You have a couple of options:
1) If you have Pro, you can use a rendertexture. 2) If you don't have Pro, you can put the hearts in another layer that is blocked on the main camera, and then use a secondary camera to render the hearts. Take a look at the 'normalized viewport' and culling options of the camera class.
Let me know if this is unclear.
Thanks. Got it working. Never thought to use more than one camera.
Why the need for the second camera? Couldn't you just parent the hearts directly to the main one and create a prefab out of it (to avoid repositioning every time), or is that the problem?
You could do that too.. but you'd need to carefully control render order, and probably either disable depth testing or clear the depth buffer before drawing the hearts.
Ah, ok, I think I understand now. Looking at the camera documentation, it seems there's a lot there to learn :D
As much as there is Unity is still like a big fluffy cloud of joy compared to really doing it yourself. I've implemented cameras and quaternions and transforms and whatnot. It's a great learning experience but it's nice to have all this great stuff more or less solid and ready to go.
Answer by flaviusxvii · Jun 07, 2011 at 02:06 PM
I'd render them with a second camera. Give it a limited viewport and disable any kind of screen clearing. It'll just draw the hearts over the top of whatever you have on your screen.
Thanks. Wish I could give out two check marks but Fla$$anonymous$$gHairball's answer had a bit more info.
No problem. I don't ever really give detailed answers. I just like to steer people towards what they need to learn to solve their own problems.