Creating a 360˚ VR App in Unity

By Anessa Petteruti

What You'll Need

  • A Cardboard headset

  • Unity3D, version 5.6 or newer

  • GoogleVR SDK for Unity

  • A 360˚ video

  • Android phone with a gyroscope to sense head movements

Steps

  • A 360˚ video has the shape of a sphere so to start, we first have to create a spherical screen to project the 360˚ video onto.

  • Create a new Unity project if you are starting from scratch or a new Scene if you want to include the 360˚ video player in an existing project.

  • Add a sphere in the Scene, placed at its center, which is Position = 0, 0, 0, with a radius of 50 (Scale = 50, 50, 50). The Camera acts as the user's eyes so it should be at the center of the screen. Therefore, set the Camera's position to 0, 0, 0. Otherwise, placing it elsewhere would be the video look distorted.

  • In order to flip the Sphere's normals to make it look like we are viewing the video from the inside of the Sphere, we need to flip its normals. To do so, create a new Material for the Sphere as well as a new Shader for this Material. The Shader will turn each of the Sphere's pixels inside out. Next, we will turn the white sphere into a video player.

  • To project the 360˚ video inside the Sphere we just created, import the 360˚ video as an mp4 file into Unity. Drag it into the Sphere. A Video Player component will appear, and the video is ready to be played!

  • Next is to view our video on our Cardboard headset. To do so, we need to create a stereoscopic view using the GoogleVR SDK. To add the SDK to our project, download and import the plugin. We need to adjust the Android settings:

    • Go to File -> Build Settings. Add the open scene, and then select Android in the list of supported platforms.

    • Click on Switch Platform.

    • Click on Player Settings. You will be able to view the Components in the Instructor panel.

    • Under Other Settings in the Player Settings' Instructor:

      • Check Virtual Reality Supported. Under Virtual Reality SDKs, select the + icon, select Cardboard to add to the list.

      • Enter the package name into the Bundle Identifier field.

      • Adjust the Minimum API Level to Android 4.4 Kit Kat (API Level 19)

    • Drag the GVRViewerMain element from the GoogleVR/Prefabs folder in the Project Browser. Assign its Position as the center of the Sphere (0, 0, 0).

  • To view the app on Android:

    • Select File -> Build Settings.

    • Plug in your Android phone into your computer and click Build & Run.

    • Launch the app, and add your phone to your Cardboard headset, and enjoy!