Skip to main content
Up and Coming
October 31, 2013

Unity GUI Package + Example

Getting GUIs working for VR in Unity seems to be a big cause of pain for people getting started. It is definitely something that needs to be simplified, so I went ahead and created a package to do just that. VRGUI should have you making GUIs in no time. Here is how it works:

1. First you need to import the VRGUI package into your project.
2. Now you need to create a script for your GUI that extends from VRGUI and implements the OnVRGUI method:

public class ExampleMenu : VRGUI
{
public override void OnVRGUI()
{
GUILayout.BeginArea(new Rect(0f, 0f, Screen.width, Screen.height));
if (GUILayout.Button("Click Me!"))
{
doSomething();
}
GUILayout.EndArea();
}
}

3. Now you need to add this script as a component of your player:
- You can attach it to the camera and it will follow your eyes, or
- You can attach it to your player controller and it will follow your player
4. You can choose to have the GUI displayed on a flat surface or a curved surface (the "Use Curved Surface" field)
5. You can choose where to position the GUI (the "GUI Position" field)
6. You can choose how much to scale the GUI (the "GUI Size" field)
7. You can choose to let the GUI accept mouse and keyboard events (the "Accept Mouse" field)

I have included an example project that shows a very simple implementation of a menu and a HUD. Hope this helps!
    This topic has been closed for replies.

    47 replies

    New Participant
    October 3, 2014
    Is there any chance of adapting this to 0.4.2?
    It does not work. I tried several modifications, but menus just don't show. :(
    Thanks!
    New Participant
    November 21, 2014
    as the class is abstract how am i meant to attach it to my player object?
    Participant
    January 18, 2015
    Does anyone know a way to hide/show this GUI depending on whether you are colliding with a cube or not? I've tried with code and with playmaker but the GUI is always displayed :/
    Participant
    January 19, 2015
    Already tried overriding (saw the hint in your previous post) but I had some issues. Thanks for the answer though.
    I could finally solve it with playmaker... because I'm a noob at coding :oops: and I have no time to learn stuff :(

    Cheers.
    New Participant
    February 7, 2015
    it doesnt work with gui.window for some reason
    New Participant
    February 24, 2015
    The package link is dead :/ can I get it from somewhere else?
    New Participant
    March 16, 2015
    Awesome man, you rock!
    New Participant
    March 20, 2015
    Thank you so much for sharing this. I do appreciate it.
    Up and Coming
    March 22, 2015
    Thank you! I find that when you add the script to both cameras.. it duplicates the cursor and text. I disabled it on one and all is well. Thanks very much for this.
    Up and Coming
    March 29, 2015
    Thank you for this package! It works wonderfully on the DK2. However, I'm running into some really weird issues with the Gear VR on device on Unity 5. In the editor on the Android Platform and Windows Platform it runs fine. However, on device, when the sample script is enabled, if you have content involving mixed shaders then the left eye is brighter or darker on content that uses a different shader. The right eye is always correct and looks identical to Editor and Windows. If you use identical shaders on all the content then it is the same in both eyes.

    I'm at a loss on how to go about troubleshooting this or how to fix it. It only occurs if the script is active. Could it just be a bug with Unity 5 and render to texture on Android? The shaders I were using were standard Unity shaders: Legacy/Bump Diffuse, Legacy/Bump Specular, Legacy/Bump Parallax. Mobile Bumped Diffuse, specular, parallax.
    Founder of Incendiary Games: http://www.incendiarygames.com/ Mobile VR Jam: http://vrjam.challengepost.com/submissi ... king-title Mobile VR Jam Form Post: viewtopic.php?f=77&t=22887