There are two ways to start a WebXR enabled project using Unity.
-
This is the simplest option, to do this, download the project and open in Unity. You can follow steps from step #7 onwards to build the project to WebXR.
-
Start by Creating a new Unity 3D Project.
In this tutorial, we cover option 2, starting from new, stepping through each step from creating a new Unity project, adding the WebXR Assets, then building to WebGL.
Open an existing project, or click on the New
button and fill in the details of the new game:
Open the menus: File > Build Settings
If it isn't, use the Unity Hub to install it for your version of Unity.
See In-editor VR playback for rapid testing for full steps.
Alternatively, download and install the WebXR-Exporter.unitypackage
from this repo and use (Assets > Import Package > Custom Package
) to import the package into your project.
If you are not upgrading a project from an older version you can uncheck /WebGLTemplates/WebVR
and /WebVR
Disable the standard default camera, so that it does not interfere with the cameras used in the WebXR prefab.
To do this, select Main Camera
from the scene's Hierarchy
; then, delete or disable the camera from the Inspector
.
Add the WebXRCameraSet
prefab (Assets > WebXR > Prefabs > WebXRCameraSet.prefab
):
The prefab contains hand controllers, VR Camera setup and other components needed for your game to work with WebXR.
This step is only needed for desktop platforms and the editor. If you don't need to support those, skip to step 7.
Copy 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.
Go to Edit > Project Settings > Player
:
Click on 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.