- Home /
2D Gui Texture under 3D object
Is it possible to render a 3D model in front a Gui Texture?
In the following images you can see the enemy status overlays the player spaceship. What I want is exactly the opposite situation, with the spaceship that stays in front of the enemy status gui.
I was struggling with the same thing a short while ago. Don't have a solution though - but I'll add a point for the correct answer. :D
Answer by efge · Feb 22, 2011 at 01:37 PM
You could try to use 2 cameras (untested):
First:
- with GUILayer
- clear to skybox or solid color
- lower draw order (depth)
Second:
- no GUILayer
- clear to "depth only" - higher draw order
Yes! Look at the "Depth only" - section of the reference: http://unity3d.com/support/documentation/Components/class-Camera.html
voted you up man but try to answer clean and complete. answering 1 question well is better than 5 answers that look like F# code. :)
Answer by Ashkan_gc · Mar 15, 2011 at 01:32 PM
there are two ways to do this. first of all you can use renderTextures. put the objects that you want to render in GUI in a seporate layer and tell the main camera to don't render that layer if you don't want them to be visible in the main scene. create another camera and tell it to render only that layer "we call it 3dGUILayer". then tell the new camera to render it's output to a rendertexture and draw the texture using a GUI.Label or GUITexture in your scene or even draw it on a GUI.Button or GUI.Label. the second way is to let the second camera (that renders 3dGUILayer) to render it's outtup to the screen but set it's clearing flag to depth only and set it's depth to a lower value to apear on top of the main camera. depth only tells the camera to render a transparent pixel in positions of the screen that it has nothing to render. then set it's position related to what you want to render to get the result that you want. renderTextures are a unity pro feature.
Answer by Sandidro · Sep 17, 2012 at 05:35 PM
set it's depth to a lower value to apear on top of the main camera. - "Cameras with lower depth are rendered before cameras with higher depth."
Answer by IzzySoft · Jan 17, 2014 at 12:51 AM
This approach sounds like it will be a headache later on if you decide you want to add allot of different GUI elements, front and back.
Why not invest some energy into finding a 3D Plane approach? See if you could always face the flat plane with a texture towards the camera, then you can re-position that flat plane in front or in the back of the ship?!
Trust me, this will be less of a head ache later on, even if the flat plane texture doesnt look pixel perfect. ;)
Your answer
Follow this Question
Related Questions
3D Object in GUI 1 Answer
GUI Label follow an object? 4 Answers
Dispalay a 3d model on GUI 0 Answers