Forum Discussion
boone188
12 years agoHonored Guest
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:
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!
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!
47 Replies
Replies have been turned off for this discussion
- KrisperExplorerReally nice, that should help a lot of people.
- jamesjExplorerI 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.
- boone188Honored Guest
"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! - jamesjExplorer
"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! - boone188Honored Guest
"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. - DarkJamesHonored GuestHey 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? :) - boone188Honored Guest
"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. - DarkJamesHonored GuestOkay cool, thanks for the info :)
- MarbasHonored GuestI 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. - boone188Honored GuestOops looks like an unneeded import statement snuck in there. I'll fix it and update the package. Thanks for pointing that out
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device