Jump to content
  • entries
  • comments
  • views

Day 34 of 100 Days of VR: Setting Up the Google Cardboard In Unity

Josh Chang


Now that we have made a conscious decision to work in VR, today I finally had the chance to play around with VR in Unity.

Today we’re going to explore setting up and using Google’s VR SDK. You might think that setting up VR would be an extremely complex process, but after going through the process, I can say that starting out is simpler than you would think!

Here’s our objective for today:

  1. Setting up support for Google Cardboard on Unity
  2. Going through Unity’s Tutorial

Let’s get started!

Step 1: Setting up Google Cardboard on Unity

For today, I’ll be going through Google’s documentation for setting up VR on Unity.

The nice thing about the Google VR SDK is that we can re-use most of the prefabs and scripts that are used with Google Cardboard and use them with Google Daydream. That’s 2 different platforms for the price of one.

Today I’ll be following Google’s official documentation on getting started on Unity.

Step 1.1: Install Unity

At this point, I’m going to assume that we all have an older version of Unity (5.6+).

  1. To support being able to run our VR App, we’re going to need to Android Build Support, if you don’t have that installed already, re-download Unity and during the installation process, choose to include Android Build Support.

Step 1.2: Adding the Google VR SDK

After we have Unity set up correctly with Android Build Support, we need to get Google’s VR assets.

  1. Download Google’s VR SDK here.

We’re looking to download the .unitypackage.


After we have the package downloaded, it’s time to add it to a Unity project.

For our case, we’re going to create a new project to play around with.

  1. In Unity create a New Project (File > New Project…)
  2. Once inside our new project, import everything from the package that we downloaded. In Unity we can import by going to Assets > Import Package > Custom Package.

Step 1.3: Configuring Unity to Run VR

Now we have imported everything we need, the last thing to do is to change some of our settings in Unity so we can run our game.

Change Our Build Setting to Build and Run Android Applications

The first thing we need to do is get Unity to run our game project on an Android platform.


  1. Open the Build Settings by going to File > Build Settings.
  2. Select Android and hit Switch Platform
  3. Wait for the game to finish re-packaging our assets for our new platform

Change Our Player Settings to Support VR

The next thing we need to do is to change our Player Settings so that we can support the specific VR SDK that we want. In our case, it’s going to be Google Cardboard.


  1. In Build Settings, next to Switch Platform, we have Player Settings, select it.
  2. In Player Settings, enable Virtual Reality Supported and then add Cardboard to our Virtual Reality SDKs
  3. Finally, in Minimum API Level, select API level 19 for the minimum Android version the device the players must have. Google Cardboard requires a minimum of level 19 and the Google Daydream Viewer requires a minimum of level 24.

Once we have everything installed, we can finally get started on taking a first look at working with VR!

Step 2: Looking Through the Unity Tutorial

Now that everything is configured, we can officially start looking through Google’s SDK Basics.

I went through the SDK basics while also going through the GVRDemo scene.

  1. In our new project go to Assets > GoogleVR > Demos > Scenes and open GVRDemo

Google provides prefabs and scripts that will take care of the VR features for you. These are all located in Assets > GooglveVR > Prefab and Scripts. Here’s a breakdown of what they and the script attached to them do:

  1. GvrEditorEmulator prefab– Allows us to control our camera like how we might control it with our headset. Hold on to the alt button to rotate your view around the camera.
  2. GvrControllerMain prefabGives us access to the Daydream controller which we can implement actions with Google’s controller API to interact with the game
  3. GvrEventSystem prefabEnables us to use Google’s input pointer system. Specifically, how our gaze/controller interacts and selects objects.
  4. GvrPointerGraphicRacyater script – This script is like a normal Graphic Raycaster that we would attach on to a UI canvas so that we can interact with our UI using our input devices (gaze or controller)
  5. GvrPointerPhysicsRaycaster script – This script shoots out a raycast directly in the middle of our screen to select something when we decide to click. We should attach this to our main camera. We must also attach Unity’s event system on each object we want to interact with when we select them.
  6. GvrControllerPointer prefab – This is the Daydream’s controller. It gives us an arm asset to imitate our controller. This prefab must the sibling of our Main Camera object where we attached our GvrPointerPhysicsRaycaster
  7. GvrReticlePointer prefab – This is the Google Cardboard’s gaze controller. It creates a dot in the middle of our screen which we use to select objects that are in the game. For this prefab to work we must make it a child of the Main Camera game object.

There are quite a couple of other prefabs and scripts, but on the high level, these are the basics we’ll need to make a VR game.

Let’s see this in action with the GvrDemo scene!

Step 2.1: Looking at the demo scene

When we open up GvrDemo, here’s what we see:


I suggest that you explore around the scene and see the objects in our hierarchy, but on the high-level summary, here’s what we have in our hierarchy that’s relevant to just the Google Cardboard (because it has Daydream assets too)

  1. GvrEditorEmulator for us to emulate head movement in VR
  2. GvrEventSystem for Unity to detect our VR inputs when we select an object
  3. Inside Player > Main Camera, we have our GvrPointerPhysicsRaycaster script which allows us to use Google’s raycasting system for 3D objects
  4. Inside the Floor Canvas game object, we have the GvrPointerGraphicRacyate for us to interact with the UI.
  5. Finally, inside Player > Main Camera > GvrReticlePointer, we have our gaze cursor for Google Cardboard that we use to interact with the game world.

The main point of this game is to click on the cube that appears in the game. When we click on the cube, it’ll be randomly moved somewhere else in the game.

The interesting part of all of this is how we can trigger the code with our Gaze.

Let’s look at the Cube and Unity’s Event Trigger system.


The Event Trigger System is a way for Unity to recognize any action taken on the game object that the Event Trigger is registered onto.

An action is something like:

  • OnPointerClick
  • OnPointerEnter
  • OnPointerExit

In our example, OnPointerClick will be triggered whenever we click on an object that has the Event Trigger attached to it.

Here’s the teleport script:

// Copyright 2014 Google Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//     http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

using UnityEngine;

using System.Collections;

public class Teleport : MonoBehaviour {
  private Vector3 startingPosition;

  public Material inactiveMaterial;
  public Material gazedAtMaterial;

  void Start() {
    startingPosition = transform.localPosition;

  public void SetGazedAt(bool gazedAt) {
    if (inactiveMaterial != null && gazedAtMaterial != null) {
      GetComponent<Renderer>().material = gazedAt ? gazedAtMaterial : inactiveMaterial;
    GetComponent<Renderer>().material.color = gazedAt ? Color.green : Color.red;

  public void Reset() {
    transform.localPosition = startingPosition;

  public void Recenter() {
    GvrEditorEmulator emulator = FindObjectOfType<GvrEditorEmulator>();
    if (emulator == null) {
#endif  // !UNITY_EDITOR

  public void TeleportRandomly() {
    Vector3 direction = Random.onUnitSphere;
    direction.y = Mathf.Clamp(direction.y, 0.5f, 1f);
    float distance = 2 * Random.value + 1.5f;
    transform.localPosition = direction * distance;

We can ignore what the code does, but the important thing that I want to bring attention to are the public functions that are available:

  • SetGazedAt()
  • Reset()
  • Recenter()
  • TeleportRandomly()

Where are these called?

Well, if you look back at our Event Trigger that’s created in Cube, we set 3 event types:

  • Pointer Enter
  • Pointer Exit
  • Pointer Click

Then whenever any of these events occur, we call our public function.

In this example, when we look at our cube, we’ll trigger the Pointer Enter event and call the SetGazedAt() function with the variable gazedAt to be true.

When we look away, we trigger the Pointer Exit event and call the SetGazedAt() function with gazedAt to be false.

Finally, if we were to click on the cube, we would trigger the Pointer Click event and call TeleportRandomly() to move our cube to a new location.


It’s surprising how un-complex this whole process is so far! I’m sure there are a lot more things to consider once we dive deeper into Unity, however for today, I think the progress we have made is sufficient.

Tomorrow, we’re going to look at how we can get the demo app to run on a phone that supports a Google Cardboard (which I assume at this point is 99% of you guys here)

Day 33 | 100 Days of VR | Day 35



Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By Rio Lloyd
      Hey all!
      we are a team of 3 looking for more members, 
      we are making an isometrical Survival RPG.
      we are looking For Members who can make low poly 3D artists who can do character models, environments, tools and more.
      if interested and want to know more email me at rioishere14@gmail.com
    • By nxrighthere
      BenchmarkNet is a console application for testing the reliable UDP networking solutions.
      Asynchronous simulation of a large number of clients Stable under high loads Simple and flexible simulation setup Detailed session information Multi-process instances Supported networking libraries:
      ENet UNet LiteNetLib Lidgren MiniUDP Hazel Photon Neutrino DarkRift More information and source code on GitHub.
      You can find the latest benchmark results on the wiki page.
    • By trapazza
      I'm trying to add some details like grass, rocks, trees, etc. to my little procedurally-generated planet. The meshes for the terrain are created from a spherified cube which is split in chunks (chunked LOD).
      To do this I've wrote a geometry shader that takes a mesh as input and uses its vertex positions as locations where the patches of grass will be placed (as textured quads).
      For an infinite flat world (not spherical) I'd use the terrain mesh as input to the geometry shader, but I've found that this won't work well on a sphere, since the vertex density is not homogeneous across the surface.
      So the main question would be: How to create a point cloud for each terrain chunk whose points were equally distributed across the chunk?
      Note: I've seen some examples where these points are calculated from intersecting a massive rain of totally random perpendicular rays from above... but I found this solution overkill, to say the least.
      Another related question would be: Is there something better/faster than the geometry shader approach, maybe using compute shaders and instancing?
    • By FedGuard
      Hello all,
      I would like to start off with thanking you all for this community. Without fora like these to assist people the already hard journey to making an own game would be exponentially more difficult. Next I would like to apologize for the long post, in advance...
      I am contemplating making a game. There, now that's out of the way, maybe some further details might be handy.
      I am not some youngster (no offence) with dreams of breaking into the industry, I am 38, have a full-time job, a wife, kid and dog so I think I am not even considered indie? However I recently found myself with additional time on my hands and decided I would try my hand at making a game.Why? Well mostly because I would like to contribute something, also because I think I have a project worth making (and of course some extra income wouldn't hurt either to be honest). The first thing I realized was, I have absolutely no relevant skill or experience. Hmm; ok, never mind, we can overcome that, right?
      I have spent a few months "researching",meaning looking at YouTube channels, reading articles and fora. Needless to say, I am more confused now than when I started. I also bought some courses (Blender, Unity, C#) and set out to make my ideas more concrete.
      I quickly discovered, I am definitely not an artist... So I decided, though I do plan to continue learning the art side eventually, I would focus on the design and development phase first. The idea being, if it takes me a year or more solely learning stuff and taking courses without actually working on my game, I would become demoralized and the risk of quitting would increase.
      So I thought I would:
      1: Keep following the courses Unity and C# while starting on the actual game development as the courses and my knowledge progress.
      2: Acquire some artwork to help me get a connection with the game and main character, and have something to helm keep me motivated. (I already did some contacting and realized this will not be cheap...). Also try to have the main character model so I can use it to start testing the initial character and game mechanics. For this I have my first concrete question. I already learned that outsourcing this will easily run up in the high hundreds or thousands of dollars... (lowest offer so far being 220 USD) I am therefore playing with the idea of purchasing https://assetstore.unity.com/packages/3d/animations/medieval-animations-mega-pack-12141 with the intention of then have an artist alter and/or add to the animations (it is for a Roman character so some shield animations are not going to work the same way.). This way I could start  with the basic character mechanics. Is this a good idea, waste of money,...? Any suggestions? I then have a related but separate question. Is it a good idea to buy Playmaker (or some other similar software I haven't yet heard of like RPGAIO), and using this for initial build, then changing/adding code as the need arises?
      3.Get a playable initial level ready as a rough demo and then starting to look for artist for level design and character/prop creation.
      I would really appreciate some input from more experienced people, and especially answers to my questions. Of course any advice is extremely welcome.
    • By GameTop
      Dirt Bike Extreme - another game made with Unity. Took about 2 months to complete.
      Take part in extreme motorcycle races across the dangerous and challenging tracks. Dirt Bike Extreme is easy to pick up but hard to master. Race, jump and crash your way and other mad rivals through the amazing tracks as you master the skills and physics of motocross in this high-speed racing adventure. Conquer challenging routes on 23 different runs, discover new bikes and become the best of the best! Over 257K downloads already!
      Windows Version:

      Mac Version:



Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!