- Home /
Gameobject shown as GUI
Hi, what is the best way to show a GameObject as a GUI? I would like a GameObject up in a corner spinning around. What's the best way to do that?
Answer by Tomer-Barkan · Oct 13, 2013 at 04:21 PM
Best way I found is to create a second camera, called GUI Camera. Then set the camera clear flags to "Depth Only", and set the camera Culling Mask to GUI. Set the depth to 1. In the main camera, set the culling mask to everything except GUI. Set the main Camera's depth to 0 (this way the GUI camera will draw over the main camera).
Now you have a camera that will only display elements with the layer "GUI", and the main camera which will display all other elements. The GUI stuff will always appear above the other stuff.
Keep the GUI camera static, and place any objects you want to display as GUI in the view area of that camera, and make their layer "GUI". Their location will remain constant regardless of how you move the main camera.
To put it in the corner, adjust the camera rect numbers. Ex: width=0.1, x=0.9; same for y. It will look distorted when you set just one, but looks fine when width&height are proportional.
Ok, thanks for the answer. Do you think this is the best idea or is it better to just have an image?
If your GUI is very simple and works well with 2D images, you can use GUITexture: http://docs.unity3d.com/Documentation/Components/class-GuiTexture.html
Their position is absolute on the screen (0 to 1, where 0 is left 1 is right), and they always draw on top of other objects.
But if you want to use more complex GUI shapes than just squares, and be able to use RayCast from the GUI camera to see if the player clicked on that complex shape, then go with what I suggested.
Ok, but I can't seem to find "GUI" under the Culling $$anonymous$$ask... $$anonymous$$ight have something to do with that I don't have pro?