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
    October 31, 2013
    Really nice, that should help a lot of people.
    Up and Coming
    November 1, 2013
    I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.
    boone188Author
    Up and Coming
    November 1, 2013
    "jamesj" wrote:
    I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.

    Oops looks like I left the JS guys out in the cold. I will work on a JS solution tonight!
    Up and Coming
    November 1, 2013
    "boone188" wrote:
    "jamesj" wrote:
    I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.

    Oops looks like I left the JS guys out in the cold. I will work on a JS solution tonight!


    Actually I figured out how to change the values in your csharp script from JS. All you have to do is put both VRGUI and the csharp script which creates the GUI into Standard Assets so it compiles first.

    Thanks so much, your script is great!
    boone188Author
    Up and Coming
    November 1, 2013
    "jamesj" wrote:
    "boone188" wrote:
    "jamesj" wrote:
    I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.

    Oops looks like I left the JS guys out in the cold. I will work on a JS solution tonight!


    Actually I figured out how to change the values in your csharp script from JS. All you have to do is put both VRGUI and the csharp script which creates the GUI into Standard Assets so it compiles first.

    Thanks so much, your script is great!

    Great to hear! Feel free to make suggestions for changes / additions if you have any.
    Up and Coming
    November 1, 2013
    Hey Boone, this looks great. What sort of license are you using for it?
    Can I just use it or do I need to credit or what? :)
    Seeing is believing
    boone188Author
    Up and Coming
    November 1, 2013
    "DarkJames" wrote:
    Hey Boone, this looks great. What sort of license are you using for it?
    Can I just use it or do I need to credit or what? :)

    No license. Just a free thing on the internet. You can credit me if you want but I don't really care.
    Up and Coming
    November 1, 2013
    Okay cool, thanks for the info :)
    Seeing is believing
    Up and Coming
    November 21, 2013
    I got an error when building the test example included in the package. (It works good in the editor)
    Im using UnityPro version 4.2.2f1


    Assets/VRGUI/Scripts/VRGUI.cs(2,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

    It builds fine when disabling line 2:


    using UnityEngine;
    //using UnityEditor;
    using System.Collections;

    But then the menu and mouse pointer don't show.
    Any idea how to fix this?

    Thanks for sharing!

    EDIT: Silly me, I was looking in the wrong direction. I expected the "click me" button to follow my eyes.
    However, I still need to disable line2 to build the example scene.
    boone188Author
    Up and Coming
    November 21, 2013
    Oops looks like an unneeded import statement snuck in there. I'll fix it and update the package. Thanks for pointing that out