Create a new Unity project called “EndlessRunner”.
Import the GoogleVR unity package into your new project. If you do not already have this unity package available on your computer, you can download it here:
Download and import the starter package for this project below:
This starter package will include a folder named “Endless Runner” with the following:
The starter scene itself named “EndlessRunnerStarter”. This scene will already have a space themed skybox set up and a single directional light.
Materials folder: contains textures/materials for lanes, power-ups and the start button.
Models folder: physical representations of obstacle/power-ups
Spaceship model source: https://www.cgtrader.com/free-3d-models/space/spacecraft-sci-fi/random-ufo
Star model source: https://www.cgtrader.com/free-3d-models/space/other/low-poly-star
Prefabs folder: prefabs that will be used a generated obstacles/power-ups.
Sky folder: contains the skybox material and textures for both editing in Unity and mobile build.
If you haven’t already, make sure that the project is for iOS or Android in your build settings.
File > Build Settings
Choose iOS or Android and click “Switch Platform” to confirm your selection.
Before closing this window, add the EndlessRunnerStarter scene by clicking “Add Open Scenes”. (If it does not show up, open this scene in the editor and then try again).
Once you have your GoogleVR package imported into the starter scene, drag the GvrMain prefab into the scene. (This can be found under “All Prefabs” in your “Favorites” folder)
Drag a GvrReticle (also present under “All Prefabs”) under the Main Camera in the GvrMain game object.
Your scene hierarchy should now look something like this:
Add a Physics Raycaster as a new component to the Main Camera. This will help us track where the player is gazing throughout the game.
The final step of setting up our scene is adding an Event System in the scene:
GameObject > UI > Event System
Remove the Standalone Input Module component from the initial EventSystem object (it’s not necessary for our project).
EventSystem should now look like this:
Add a Gaze Input Module and Touch Input Module:
The Gaze Input Module is included in the GoogleVR SDK and will help process the player’s gaze input events.
The Touch Input Module is included in the iOS Unity package and processes the user touching the devices screen. The Cardboard viewer’s trigger actually just hits the screen to create input events, so it utilizes this module.