Create WebVR Projects in Unity

Unity-WebVR-Assets

WebVR template and assets for creating WebVR-enabled Unity projects.

Download from GitHub

How to Use

Copy WebGL template

  • Windows users: Overwrite C:\Program Files\Unity\Editor\Data\PlaybackEngines\webglsupport\BuildTools\WebGLTemplates with WebGLTemplates from this repository.

Set build platform to WebGL

From File > Build Settings, select WebGL as the platform.

WebGL!

Set WebGL template

  1. Open Edit > Project Settings > Player to access the Player settings.
  2. Under Resolution and Presentation, select WebVR as your WebGL template.

Template!

Set up WebVR camera

  1. Copy WebVRCameraSet.prefab from the WebVRAssets/prefabs folder into your Assets.
  2. Replace your default Main Camera with the WebVRCameraSet prefab.
  3. Copy WebVRAssets/Scripts/StereoCamera.cs into your Assets, and ensure that it is attached to the parent node of the prefab.

Camera!

Build and run

Once your project finishes building, open the generated index.html in a WebVR-enabled browser.

Local Development Notes

To copy the files over to your project:

UNITY_WEBVR_PROJECT=$HOME'/my-project/' sync.sh

I couldn’t get the above WebVR project working with navigation, but I got a WebGL project working.

Here’s the live demo.

https://codetricity.github.io/webvr-demo/

Please provide advice on how to get the WebVR (not WebGL) demo working.

1 Like

I’ve been going through the Unity thread on their support of WebVR.

https://forum.unity3d.com/threads/webgl-and-webvr.390445/

Here’s the relevant pieces:

  • WebGL exists now, but WebVR is taking a while to implement
  • WebVR works with the plugin, but mouse navigation is not enabled. Navigation needs to be implemented in JavaScript

Regarding controller support: original

I don’t think it has controller support - but it would be possible to implement that in JavaScript yourself.

It appears that Oculus Rift and gamepad controls work.

Regarding timing of WebVR support in Unity 5.7 - original post

It will not be in 2017.1 and probably also not in 2017.2.

Other:
Here’s an article from Anthony Palma, the CEO of Jump on building a game with Unity using the WebVR hack.

The article above references this GitHub repository for a WebVR template using the hack.

1 Like

Hi, I followed this instruction and did every single step, but it doesn’t work. Can I ask what is the local development notes is? Do I need to do something with it??

Did it not build? Or, did you just have problems with the controllers in the WebVR application? That article is from November 2016. At the time I looked at it, the WebVR controllers were not enabled.

Unity was also working on enabling WebVR, so they may have released official support. If there isn’t an official solution now, I can look at this again.

If you’re building a simple app, then using A-Frame is a better solution if you’re building something for the Web. If it’s a fullblown Unity app, then you should also verify that the status of the controllers are.

What is your target, HTC Vive?

I just took a look at this one does have support for Oculus Rift controllers.

Do you have a Rift?

Hello ,
UNITY_WEBVR_PROJECT=$HOME’/my-project/’ sync.sh

Share me path where i copy the file of sync.sh

Thanks

Hello,
I have followed this step by step, but it did not work. I used HTC VIVE and I got an error with “Unity_WEBGL_LOADER_GLUE”. If you have any solution to this problem, I really appreciate it.
Thank you in advance.