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

    Participant
    April 10, 2014
    Excellent package!
    I searched such a thing for a while : and it's awsome!

    Just a question: my game is implemented to switch between screen and oculus and I have a script which cas a ray from mouse to gameobjects to display some information about it.
    When I implement your package for the pause menu, I then have 2 mouse cursors the first for pointing objects, the second for clicking on the pause menu... which is weird...

    the problem is that my raycast script is in js... and I guess it comes from its OnGUI function.

    Have you got a version like "VRGUI.js"?
    Inspiring
    April 25, 2014
    Subscribed! :)
    Up and Coming
    August 3, 2014
    Thank you so much for this Boone188, The standard GUI was not working with 0.4.0, but that just got me working on a new GUI and you really made it easy on me and others.
    Riftmax Theater 4D Multiplayer VR Cinema! http://www.riftmax.com - Latest DK2-ready version 0.415(11/27/2014)
    Up and Coming
    August 3, 2014
    "MikeArms24" wrote:
    Thank you so much for this Boone188, The standard GUI was not working with 0.4.0, but that just got me working on a new GUI and you really made it easy on me and others.


    Remember a new GUI is coming out with 4.6. On the Unity forum, they took down the sticky thread to this site: http://isthenewguioutyet.com
    So maybe they are actually close. It should help with Rift GUIs.
    New Participant
    August 4, 2014
    Unfortunately this sample doesn't work if you use GUILayout.Window since the actual draw calls are deferred and don't happen on the rendersurface... I haven't found a way to make that work yet. Was anyone ever able to make Unity GUI Windows work with Oculus?
    Up and Coming
    August 10, 2014
    I have the same problem with GUI.Window. I guess we're out of luck for now. Hopefully one day DK2 will be compatible with the standard user interface in Unity.
    Riftmax Theater 4D Multiplayer VR Cinema! http://www.riftmax.com - Latest DK2-ready version 0.415(11/27/2014)
    Participant
    August 20, 2014
    I tried VRGUI with SDK0.4.1.
    GUI.Button and GUILayout.Button can be used.

    GUI.Button and GUILayout.Button test project.
    https://mega.co.nz/#!nY1giaIS!CDy0oFzTlOkWcaf24za1ThEAYyXJxg9GcRRU7IjiejU
    KaleidoPlayer More immersive and realistic to 2D and 3D videos
    New Participant
    August 20, 2014
    Hello,

    great that you made the work of this example. but before I will adapt my menu to your Script I would like to know if anybody of you is able to use the Scene selection functon of the OVR Main Menu script? If not I stop wasting my time and adapt to your script.
    New Participant
    August 21, 2014
    Hi,

    I found your Package really helpful, but I have a problem.
    The position of the mouse and the cursor that is projected on the surface don't correspond.

    I tried to solve that problem, but I don't quit understand what is happening in your code. Why do you need that Screen.height? I try with the Input.mousePosition.y, it is moving the opposite way? Why???
     cursorPosition = new Vector2(Input.mousePosition.x,Screen.height - Input.mousePosition.y);


    Could someone please help???
    Participant
    August 21, 2014
    If you use mouse,please check this line.

    File:OVR/Scripts/OVRMainMenu.cs

    // Make sure to hide cursor
    if(Application.isEditor == false)
    {
    Screen.showCursor = false;
    //Screen.lockCursor = true; // comment out :-)
    }
    KaleidoPlayer More immersive and realistic to 2D and 3D videos