Google Cardboard Hello World Tutorial
By Ruiqi Mao
1. Create a new Unity Project. Make sure the 3D option is selected.
2. Save the current scene with any name you'd like.
3. Go to File > Build Settings. Choose "Android" under "Platforms", and click "Switch Platform". This tells Unity that we intend to build for Android, which is what Google Cardboard runs off of.
4. Click on "Player Settings". A sidebar should open on the right.
5. Go down to "Other Settings", choose a package name, and change the Minimum API Level to "Android 4.4 'Kit Kat' (API level 19)".
6. Go down to "XR Settings", and turn on "Virtual Reality Supported".
7. Add "Cardboard" as a Virtual Reality SDK.
8. Download the latest GoogleVR SDK for Unity from https://github.com/googlevr/gvr-unity-sdk/releases. The extension should be ".unitypackage".
9. In Unity, go to Assets > Import Package > Custom Package..., and choose the GoogleVR SDK you just downloaded.
10. A dialog with a list of files should show up. Leave everything checked and click "Import".
11. A "GoogleVR" folder should now appear in the Assets pane at the bottom.
12. Inside the Assets pane, go to GoogleVR > Prefabs, then drag "GvrEditorEmulator" to the "Hierarchy" pane on the left. This will let us run programs on the development machine without having to upload to an Android device every time we want to test something.
13. Then, go to GoogleVR > Prefabs > EventSystem, then drag "GvrEventSystem" to the Hierarchy pane. This will allow the GoogleVR system to process events that can happen, such as looking at an object.
14. Then, go to GoogleVR > Prefabs > Cardboard and drag "GvrReticlePointer" to the "Hierarchy" pane on the left, but make sure it is placed within "Main Camera". This will put a circle on the screen that tells us where we're looking.
15. We can test now! Click the Play button at the top of the editor. It will take a few seconds to load, then show us what our "game" looks like. You can move the camera by holding down Alt and moving the mouse around. You should see a pretty boring world with a white circle in the center that tells us where we're looking.
16. This is boring. Let's add something to our scene! Click the Play button again to go back to the editor.
17. We're going to add an object to our scene. But before we do that, we want to make sure we know where our camera is. Select "Main Camera" in the Hierarchy pane, then look over to the right in the "Inspector" pane. Change the position to be (0, 0, 0).
Note: This does not actually change the location of the camera in VR. With GoogleVR, the camera is always at the origin regardless of where the Main Camera is. It can only be changed by placing the Main Camera as a subobject within another object, which is beyond the scope of the tutorial. We are doing this step to make development easier.
18. Right click on the Hierarchy pane and select 3D Object > 3D Text. This will create some text in our world.
19. Select the text that we just made and move it to (0, 0, 10).
20. We can actually preview what the camera will see! Select the camera, and you should see an outline of the camera frustum (the pyramid-like shape that encompasses what the camera can see), as well as a small preview of the scene.
21. Let's test this again. Run the scene again with the Play button and look around to make sure we can see the text.
22. Now let's try this on an actual device! Grab your compatible Android device and connect it to your computer.
23. Now go to the top and select File > Build & Run. Choose a name for the application package ("helloworld.apk"), and click "Save".
24. Your device should launch the application and show something like this!
25. Congratulations! You've successfully made a Google Cardboard VR application!
26. If you'd like to make your application a little more interactive, take a look at the next part: Google Cardboard Interactivity Tutorial