Quickstart for Google Cardboard for Unity

This guide shows you how to use the Google Cardboard XR Plugin for Unity for Unity to create your own Virtual Reality (VR) experiences.

You can use the Cardboard SDK to turn a smartphone into a VR platform. A smartphone can display 3D scenes with stereoscopic rendering, track and react to head movements, and interact with apps by detecting when the user presses the viewer button.

To get started, you'll use HelloCardboard, a demo game that demonstrates the core features of the Cardboard SDK. In the game, users look around a virtual world to find and collect objects. It shows you how to:

  • Set up your development environment
  • Download and build the demo app
  • Scan the QR code of a Cardboard viewer to save its parameters
  • Track the user’s head movements
  • Render stereoscopic images by setting the correct distortion for each eye

Set up your development environment

Software requirements:

Import the SDK and create a new project

Follow these steps to import the Unity SDK and create a new project.

  1. Open Unity and create a new 3D project.
  2. In Unity, go to Window > Package Manager.
  3. Click + and select Add package from git URL.
  4. Paste https://github.com/googlevr/cardboard-xr-plugin.git into the text entry field.
    The package should be added to the installed packages.
  5. Navigate to the Google Cardboard XR Plugin for Unity package. In the Samples section, choose Import into Project.
    The sample assets should be loaded into Assets/Samples/Google Cardboard/1.1.0/Hello Cardboard/Assets.
  6. Navigate to Assets/Samples/Google Cardboard/1.1.0/Hello Cardboard/Assets/Scenes, select Add Open Scenes, and choose HelloCardboard to open the sample scene.

Configuring Android project settings

Navigate to File > Build Settings.

  1. Select Android and choose Switch Platform.
  2. Select Add Open Scenes and choose HelloCardboard.

Player Settings

Navigate to Project Settings > Player > Resolution and Presentation.

  1. Set the Default Orientation to Landscape Left.
  2. Navigate to Project Settings > Player > Splash Image > Show Splash Screen and set the value to false. Note that this option is only available in Unity Plus and Unity Pro.

Other Settings

Navigate to Player > Other Settings.

  1. Select only OpenGLES2 in Graphics APIs.
  2. Select IL2CPP in Scripting Backend.
  3. Select both ARMv7 and ARM64 in Target Architectures.
  4. Select Require in Internet Access.
  5. Specify your company domain under Package Name.

Publishing Settings

Navigate to Player > Publishing Settings.

  1. Select Custom Main Gradle Template in the Build section.
  2. Add the following lines to the dependencies section of Assets/Plugins/Android/mainTemplate.gradle:

      implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support:support-v4:28.0.0'
      implementation 'com.google.android.gms:play-services-vision:15.0.2'
      implementation 'com.google.protobuf:protobuf-lite:3.0.0'
    

XR Plug-in Management Settings

Navigate to Project Settings > XR Plug-in Management settings.

  1. Select Cardboard XR Plugin under Plug-in Providers.

Build your project

Navigate to File > Build Settings.

  1. Select Build, or choose a device and select Build and Run.

Configuring iOS project settings

Navigate to File > Build Settings.

  1. Select iOS and choose Switch Platform.
  2. Select Add Open Scenes and choose HelloCardboard.

Player Settings

Navigate to Project Settings > Player > Resolution and Presentation.

  1. Set the Default Orientation to Landscape Left.
  2. Navigate to Project Settings > Player > Splash Image > Show Splash Screen and set the value to false. Note that this option is only available in Unity Plus and Unity Pro.

Other Settings

Navigate to Player > Other Settings.

  1. Disable the Auto Graphics API option.
  2. Choose only OpenGLES2 in Graphics APIs.
  3. In Camera Usage Description, write Used to scan the QR codes.
  4. In Target minimum iOS Version, write 11.0.
  5. Specify your company domain under Package Name.

XR Plug-in Management Settings

Navigate to XR Plug-in Management settings.

  1. Select Cardboard XR Plugin under Plug-in Providers.

Build your project

Navigate to File > Build Settings.

  1. Select Build or Build and Run.

Next steps