Setting up a Unity project for WebVR
There are two ways to start a WebVR enabled project using Unity.
In this tutorial, we cover option 2, starting from new, stepping through each step from creating a new Unity project, adding the WebVR Assets, then building to WebVR.
1. Create a new Unity 3D project.
Open an existing project, or click on the
New button and fill in the details of the new game:
2. Ensure that WebGL platform support is installed.
Open the menus:
File > Build Settings
3. Enable Virtual Reality support in Unity.
See In-editor VR playback for rapid testing for full steps.
4. Download the assets from the Unity Asset store.
Alternatively, download and install the
WebVR-Assets.unitypackage from this repo and use (
Assets > Import Package > Custom Package) to import the package into your project.
5. Add the WebVR prefab to your scene.
Disable the standard default camera, so that it does not interfere with the cameras used in the WebVR prefab.
To do this, select
Main Camera from the scene's
Hierarchy; then, delete or disable the camera from the
WebVRCameraSet prefab (
Assets > WebVR > Prefabs > WebVRCameraSet.prefab):
The prefab contains hand controllers, VR Camera setup and other components needed for your game to work with WebVR.
6. Add Input Manager settings to your project.
InputManager.asset into your Project
/ProjectSettings folder. This will add pre-configured Unity Input Manager input axes needed for controllers to work.
See Controllers and Input System for more details about how this works.
7. You're Unity project is setup. Play to see the result!
8. Build your project to WebVR
Select the WebVR template from player settings.
Edit > Project Settings > Player:
Build and run your project in the browser!
File > Build & Run, select a destination folder and Unity will compile your code and and launch the game in your default browser. If you want to open the game in another browser, copy and paste the URL of the game.
Under the hood, when clicking
Build & Run, Unity will place all the needed files in the selected folder and will spin up a development web server pointing there. If you want to provide your own server, choose
File > Build instead.