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
    April 8, 2015
    Still can't get it to work on the Gear VR. :(
    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
    Inspiring
    April 8, 2015
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    July 17, 2015
    Im getting this error when adding script

    Assets/VRGUI/vrgui2.cs(10,17): error CS0103: The name `GUILayout' does not exist in the current context




    Im trying to get my OnGUI to work in VR Will even pay for someone who can help me. Im a newb at unity, i do graphics but I need VR for a presentation and my other guy that codes doesnt have a oculus!

    If I add just VRGUI without the script in the instructions, I get.

    GameObject (named 'Main Camera') references runtime script in scene file. Fixing!
    UnityEditor.HostView:OnGUI()

    The class named 'VRGUI' is abstract. The script class can't be abstract!
    UnityEditor.HostView:OnGUI()


    The class named 'VRGUI' is abstract. The script class can't be abstract!


    Again, will pay for any help to get this to work.
    New Participant
    November 10, 2015
    I know this is an old thread, but anyone was able to make it work with GUI.Window?

    Thanks in advance.
    New Participant
    February 17, 2016
    Hello,

    can we integrate with OVRVisionGuideMessage component to set a background for it ?

    thanks in advance
    New Participant
    February 17, 2016
    I am using unity with oculus i need to show a text at the middle of the screen with a background how can we do it?
    New Participant
    December 17, 2021

    haha