- Home /
GUI and stereoscopic 3D
I'm trying to work on GUI for a stereoscopic 3d package(It includes 2 cameras, left and right and some scripts which divides the screen into two and each shows related camera view. The problem is GUI is rendered on the entire screen rather to be rendered on each camera. How can i tell each camera to render GUI separately in its own screen?
Thanks.
Answer by Wolfram · Sep 24, 2010 at 09:43 AM
You can reference the actual pixel Rect of any camera with Camera.pixelRect. So to create a centered button of half the camera's dimensions in each camera, attach a script like this to each camera where you want the button to show:
var myRect:Rect; void Start(){ myRect=camera.pixelRect; myRect.x+=myRect.width/4; myRect.y+=myRect.height/4; myRect.width/=2; myRect.height/=2; }
void OnGUI(){
if(GUI.Button(myRect,"blub")){
// do something
}
}
Another ppossibility would be to use the "older" GUIText/GUITexture objects instead of UnityGUI, which are always placed in a normalized coordinate system relative to each camera. However, I don't think you can selectively show such a object on only one camera, or even at different relative positions within these cameras. You can only switch all such objects on or off for a camera globally, by enabling/disabling the camera's GUILayer.
This seems to work! the only problem I'm afraid to face while presenting on a 3d projector is that, in this code we are creating two separate buttons ins$$anonymous$$d of having one appearing in both, therefore there might a possibility of two buttons run a same function at the same time and cause some errors? but other than that it looks the way it should be. I'll try to check it first on a 3d projector. thanks!
Not sure how you're going to interact while doing the 3D projection. But I guess if you're doing passive stereo with the two stereo views rendered next to each other, you would interact only in one of these views, and therefore only one of the buttons will receive interaction events. Otherwise you could use a flag to distinguish between GUI elements shown in the left/right view, which could also help you to render these buttons at different positions (e.g., if you don't want them to be shown at screen depth).
Your answer
Follow this Question
Related Questions
GUI.Label positioning for many device resolutions 1 Answer
Simple Menu(understanding GUI) 2 Answers
How to create an agenda or timetable system? 1 Answer
Flash 2D Interface on Top of Unity 3 Answers
If not over interface 2 Answers