Jump to content
  • Advertisement
  • 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 Nick Griffith
      I'm making a 2d platformer game as a learning experience, and I need a character and some backgrounds.
      The idea is a person on the brink of death "running" through his memories. The background is his memories.
      This game will make minimal revenue, because it'll be a free mobile game.
      I'll give you more details if you respond.
    • By GameDev.net
      Search GameDev.net directly from the Unity Editor with the GameDev.net Search plugin!
      Customize your search for all content on GameDev.net, only the latest, or the most relevant. Or, narrow your search to specific GameDev.net content:
      Blogs Articles Forums News Contractors Projects and more!
    • By Heretic Arts
      We are an American based videogame development team that crafts games utilizing neural networks, handcrafted art, studio quality audio, and immersive storytelling to provide the player with an unforgettable experience. Our current team comprises of a Software Engineer, Designer, Producer, Audio Engineer, and a systems admin. Obviously we are missing an art staff! Now, that being said, we have outsourced our concept art for the game to an experienced artist. We are wanting talent to join us to take it the rest of the way with animation and art. If you are interested in joining the team and feel that you are ready to work along a committed team, send a sample of your work and contact information to HereticRecruitment@HereticArts.com. 
      Job Specifics: 
      Unpaid. This is normal. We all have fulltime careers outside of the team, but if there is money to be made upon release, it will be split evenly - no questions asked.  All expenses are paid by Administrative Team (GSuite account). So no worries - We want someone to join, have fun and create with us! Expectations of meeting weekly (via internet) and taking direction from producer.  Open minded  
      Skill sets: 
      Experience in designing and creating character art.  Full adobe suite.  Maya experience preferred.  Experience with developing for the Unity Engine.  Willing to work with design team to incorporate their ideas into art.  Knowledge of game design documentation and how it pertains to art creation.  In depth sprite animation knowledge. 
    • By GameDev.net
      GameDaily.Biz spoke to Improbable about its new shortcuts to multiplayer game development for Unity and Unreal. 

      Improbable helps game developers build believable online worlds with its bespoke technology, SpatialOS. Now, that task is much easier and accessible for those building games on the technology with the recent release of the SpatialOS Game Development Kit (GDK) for Unity. With these kits, Improbable hopes that developers find it easier to create vast, dynamic and unique worlds.
      This GDK for Unity includes a 200-gamer, first-person project that allows developers to experiment and tinker with their ideas for what their vision of a multiplayer game will look like.
      GameDaily.Biz met with Improbable’s Head of Product Marketing, Paul Thomas, and Head of Comms, Daniel Nye Griffiths, to speak about the SpatialOS GDK for Unity, as well as the upcoming launch of the SpatialOS GDK for Unreal Engine.
      In its first week, the SpatialOS GDK for Unity achieved over 2,000 developer sign ups to use it. “What we're trying to do is basically make it really fast for people to build multiplayer games,” said Thomas. “It comes with all the multiplayer networking so that developers don’t have to do any multiplayer networking. It comes with feature modules to allow [easy] solutions to common multiplayer problems, like player movement and shooting. And it comes with a cool starter project where you have 200 players in a free-for-all scenario. You can obviously use the power of SpatialOS to scale that project up to more players, with NPCs, and things like that. It gives people a really good base to start building multiplayer games.”
      There are several games currently in development or early access that utilize SpatialOS. The first into Early Access was Spilt Milk Studios’ Lazarus, a space MMO where the player becomes a pilot in a universe that ends every week, complete with a map that’s twice the size of Austria. Additionally, Bossa Studios released its survival exploration game Worlds Adrift into Steam Early Access earlier this year.
      Also using SpatialOS is Scavengers from Midwinter Entertainment, a studio founded by former 343 Industries studio head and Halo 4 Creative Director, Josh Holmes; the game is heavily inspired by his Halo 5: Guardians’ multiplayer mode, Warzone. Right alongside that company, Berlin-based Klang Studios is working on Seed, a simulation MMO that, according to its developers, lets players “interact and collaborate to create a world driven by real emotion and aspiration.”
      According to Thomas, for those looking to use the SpatialOS GDK for Unity, there is no limit to  what their games can do with Improbable’s tech.
      “What we're doing is expanding the possible gameplay you can do. Traditionally, when you make a multiplayer game, you're constrained by one single server. So you can say you have a 64-player game with a handful of NPCs or you could have a world that's 3km by 3km. With Spatial, you can go beyond that, test a much broader canvas to start thinking about different gameplay.”
      “You can go for a massive online persistent MMO with 10,000 players and hundreds of thousands of NPCs, something very, very vast and big like that. But you can also have smaller experiences. For example, there's a lot of interesting space in just extending what you see in the Battle Royale genre and session-based gameplay.”
      Thomas continued: “Our partners at Automaton have a game in development called Mavericks. The interesting thing there is they have a Battle Royale with 1,000 people, but what I really find interesting is the gameplay mechanics they've put in, like footprints so you can track people. They've added a cool fire propagation mechanic so you can start a fire that  spreads across the map and changes the world. Or you can add destructible buildings and things like that.”
      “So I think even looking at smaller scale games, we add a lot of value in terms of the new gameplay you can start adding. I'm just interested to see what people do with this extra power - what they can come up with.”
      While Battle Royale games and MMOs are obvious standouts for genres that best fit with SpatialOS, Thomas introduced some other ideas of genres that could benefit from the technology.
      “I also think there's a space for very interesting MMORTSs as well,” he said. “An RTS where you have persistent systems, like telling AIs to do things and then coming back to them a week later and seeing what's happened is an interesting space.”
      “I also see interesting mobile experiences that could come up. Having these worlds where you lay down some interesting things and then come back a few weeks later to see how they've evolved and changed, and the massive player interaction. Say for example with Pokemon Go, we can actually roam around the world and battle on the streets. I can see something like that working very well. Again, these are just ideas we've had and talked to people about. It's about giving people that flexibility and the ability to explore these ideas.”
      Klang’s Seed
      Griffiths added the possibility of events in a game that will have a massive, rippling, and lasting impact on its world as something that has people excited. One example he gives is how someone on one side of the map can do something that’ll have a knock-on effect for the rest of the world in real time.
      “There's a whole bunch of different angles you can take, some of which are about much larger player numbers or a much larger map, but there are other things you can do which are taking a relatively constrained game experience, a smaller map, a smaller number of players and adding richness to the game as well.”
      In fact, this is something that Thomas refers to as a “persistent in memory database,” meaning that for every object in the game world, there’s a history. Two examples cited by Thomas: “...a player could chop down a tree and that tree stays disappeared forever. Or a player can kill a big monster that was raiding a town and that town no longer gets raided by that monster, and this changes the dynamics of the world. Worlds can have a history. That means players can have a lot more meaning in these MMO worlds.”
      “Normally in MMOs, they're kinda like roller coaster rides: you go into a dungeon, you kill the boss and that guy respawns. It all resets,” Thomas continues. “But in Spatial MMOs, you could have these persistent effects that should change the gameplay meaningfully for all the rest of the player base.”
      “The other one I think that is interesting is the level of dynamism that you could have. So because you can have so much more server-side compute, you could potentially have NPCs roaming around the world changing their mind and deciding all of a sudden, 'oh, we're going to attack this player's base' or 'we're gonna go attack this town' and they have a lot more range and emotion and intelligence to them that you'd not see in other MMOs.
      “Normally in MMOs, NPCs sit there tethered. You go near them and they come and attack you, you run away, and they go back to where they were. In a Spatial MMO, that NPC can trace you across the whole map or a group of them can decide to get together and attack someone..”

      Bossa Studios' Worlds Adrift

      Next week, Improbable plans to launch its SpatialOS GDK for Unreal Engine, which will have a big focus on ease of use for access to Unreal, as well as a big emphasis on porting your projects to SpatialOS.
      “One of the things we'll be trying to push is a porting guide so you'll be able to take your existing Unreal game, move it onto SpatialOS and then you can grow to expand it with new and extra gameplay,” says Thomas. “ You can bring across your existing Unreal game and it feels very, very native and similar to Unreal if you're familiar with Unreal.”
      Griffiths continued, explaining how testing these experiences includes free cloud deployments, to a certain point. “If you're developing in SpatialOS in other ways, we provide a sandbox environment so you can get your game running. When you’re happy, you can port it over and sort of experiment with it in a free sandbox environment with a small number of cores to get started.”
      Based on what we learned, Improbable’s SpatialOS GDK for Unity will give developers enhanced flexibility to produce more in depth and engaging videos games. That said, we look forward to catching up with the company in the near future to see how this exciting technology is being used in the different games that we play.
    • By LonelyStep
      Thought I'd reach out for some feedback on my little project. This is an android two-player game for top-down boxing matches. The core mechanics are all that I have accomplished thus far, later I want to add different configurations for your boxer (special effects, increased health or damage, etc) and maybe even a single player AI to practice against.



      Right now the gameplay feedback I'm looking for is on the fundamental mechanics of the game.

      One area of particular concern is the window of opportunity for a player to block after their opponent has begun a punch. Currently that window is one-tenth of a second, otherwise you will be to late to counter their blow. I want it to be difficult to successfully pull off a block and have it be something that requires real attention to accomplish. I'm wondering though if it isn't too difficult right now, which may encourage mindless button mashing, which is certainly not what I want to condone.

      Another consideration is whether having three main actions (block, attack, charge) provides a good balance. My idea with having three main areas is that your two thumbs will have to leave one section uncovered at all times. This should result in hand movements that telegraph actions to the opponent.

      Aside from these, any other constructive criticism is very welcome.

      My game can be found at the Google Play Store here:

      NOTE There is a known graphics error when performing a special punch. There are no doubt other unknown errors as well.

        Thank you for your time, I hope you'll be able to find some fun in this little game!

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!