- Home /
The question is answered, right answer was accepted
Rendering 3D objects on the GUI
What is the best way to render a 3D object/prefab on the GUI layer, or make it look like it is apart of the GUI.
Here is what i have so far:
The object renders above the GUI components gameobject but not the GUI from script.
u could move it with u to make it look like its always there. but why owuld u want to have a 3d object on a gui layer.
Answer by Bunny83 · Aug 19, 2012 at 03:22 AM
It should be no problem to render a second camera manually. Just setup your camera and disable it so it isn't rendered automatically.
In OnGUI you can do this:
void OnGUI()
{
// [other GUI stuff]
if (Event.current.type == EventType.Repaint)
{
objCamera.Render();
}
}
This would render the camera at it's setup position above the other GUI elements that are drawn in ObGUI ;)
That's one of the big advantages of the immediate-mode ;)
by disable do u mean disable the gameobject or the camera component?
@Novack: What clearflags does your second camera have? Also, do you render the camera to the full screen, or have you set the rect or pixelRect.
In OnGUI things are drawn in order, so when you draw your GUI stuff first and render a camera to the full screen afterwards it will of course overwrite the whole screen. Try it with clearflags "None" and change the rectangle the camera should render to.
I use this myself quite oftenm even on Android ;)
you could also render depth only, witch is what i used.
Yes, in most cases you will use "Depth only" or you could get in trouble with the depth buffer ;)
Answer by Khada · Aug 17, 2012 at 08:00 PM
Create a new camera, set it to orthographic, set its depth higher/lower than you main cam (depends on your setup) and draw only the 3D GUI objects with that camera (you can use the culling mask on the cameras for this). On the camera with the higher depth value, set its clear flag to 'depth only'.
I would need much more detail to give a more specific answer.
You're quite active! Hopefully this was the last answer i've to publish in the moderation queue ;) You should have enough karma now...
It's great to have some more active people here ;)
Haha! Sorry to make you do all that. Sadly, having my answers come late meant I missed out on a few karma opportunities which meant I still needed modding. I intend to be reasonably active. I used to do this sort of a thing a little bit over on the XNA forums. Thanks for the modding :)
i updated the question do u have a solution to that, the depth adjustment is not working in this situation.
Answer by Demigiant · Aug 17, 2012 at 07:15 PM
Best way would be to use a separate camera just for your 3D object (probably orthographic, depending on your needs), and position it relatively to the GUI.
Else, but I'm not sure if it's really doable, if you have Unity Pro you could still use a separate cam only for your object, render it to texture, and place that texture somewhere in your GUI.
i was thinking of having a camera for the object but i was wondering if there was an easier way. i dont hav pro, but i plan to get it.
but the problem is how i get this to render above the GUI layer
That's what a cameras 'Depth' controls, it's draw order. You may need to add more than one camera to get the desired effect (think of each camera as a layer).
i tried adjusting the depth, but it never got infont of the GUI, i also tried removing the GUIlayer component from the camera. i added a pic to the question.
that's too bad, i dont hav pro, so i'll probably just render a still image to use until i get pro.
Follow this Question
Related Questions
2D Arrow pointing at 3D Position 1 Answer
Drawing GUI Text using Javascript 2 Answers
3D ^ Custom GUIText/Label or Making a Score System without using GUI? 0 Answers
3D object in uGUI 3 Answers
3D Object in GUI 1 Answer