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

    Up and Coming
    November 23, 2013
    this is a great tool! thank you for the great work!

    i just got i to work but i'm having one problem. Im using the code in this thread and i attached it to the OVRCameraController. But it does not follow eyes when i look up or down, just when i look left and right. what am i missing?
    boone188Author
    Up and Coming
    November 23, 2013
    "saarwii" wrote:
    this is a great tool! thank you for the great work!

    i just got i to work but i'm having one problem. Im using the code in this thread and i attached it to the OVRCameraController. But it does not follow eyes when i look up or down, just when i look left and right. what am i missing?

    If you want a GUI to follow the eyes in every direction, you should attach it to one of the OVRCameras. Typically people use "CameraRight".
    Up and Coming
    November 23, 2013
    thanks! should have looked at your example project first :) everything was there
    New Participant
    November 24, 2013
    Thank you! This really helps me with my project! :)
    Up and Coming
    December 6, 2013
    I have accept mouse input checked but I can't seem to click any of my buttons! Id also like to add "look to select" type interactions with my menu elements in the VRGUI but I am not sure how to go about it with VRGUI.

    I tried to skip this problem by rendering my buttons to boxes, and putting them in front of the curved plane. Im shooting a ray out from the oculus cameras and detecting collisions with the boxes. This works except that the texture on the plane covers up the buttons, making them hard to see (both are somewhat transparent). I can't get the buttons to show up OVER the UI, and I can't get the buttons to work INSIDE the UI.
    boone188Author
    Up and Coming
    December 7, 2013
    "jamesj" wrote:
    I have accept mouse input checked but I can't seem to click any of my buttons! Id also like to add "look to select" type interactions with my menu elements in the VRGUI but I am not sure how to go about it with VRGUI.

    I tried to skip this problem by rendering my buttons to boxes, and putting them in front of the curved plane. Im shooting a ray out from the oculus cameras and detecting collisions with the boxes. This works except that the texture on the plane covers up the buttons, making them hard to see (both are somewhat transparent). I can't get the buttons to show up OVER the UI, and I can't get the buttons to work INSIDE the UI.


    Strange that the mouse input wouldn't work. Did the demo scene work? I can definitely add look-control. That was something I planned on adding from the beginning. If you could elaborate on how you would like it implemented I would appreciate it.
    Up and Coming
    December 8, 2013
    I ended up implementing my own look control. I think stuff is weird for me since I'm including your c# scripts but using JS to interact with them. I just cast a ray from the camera to the curved UI plane to figure out which buttons the user was looking at. Never did figure out why mouse click didn't work.
    boone188Author
    Up and Coming
    December 9, 2013
    "jamesj" wrote:
    I ended up implementing my own look control. I think stuff is weird for me since I'm including your c# scripts but using JS to interact with them. I just cast a ray from the camera to the curved UI plane to figure out which buttons the user was looking at. Never did figure out why mouse click didn't work.

    That's cool. I will still probably implement this at some point.
    Up and Coming
    December 9, 2013
    Cool! Let me know if you update the script.
    Up and Coming
    February 24, 2014
    Thanks a lot for the package. Only thing that I saw it didn't have was the ability to set the layer of the guiRenderPlane. I just added a public int to VRGUI.cs, and assined that int into the guiRenderPlane.layer in Initialize().