Creating the MeMyselfEye player prefab
Most VR toolkits provide a preconfigured player camera rig as a prefab that you can insert into your scene. This rig replaces the default Main Camera. For this book, since we do not know which particular devices and platforms you are targeting, we will make our own camera rig. Let's called it MeMyselfEye (hey, this is VR!). This will be helpful later on, and it will simplify our conversations in this book, since different VR devices may use different camera assets. Like an empty vessel for your VR soul...
We will reuse this MeMyselfEye prefab in chapters throughout the book as a convenient generic VR camera asset in our projects.
A prefab is a reusable (prefabricated) object retained in your project's Assets folder that can be added one or more times into project scenes. Let's create the object using the following steps:
- Open Unity and the project from the last chapter. Then, open the diorama scene by navigating to File | Open Scene (or double-click on the scene object in the Project panel, under Assets).
- From the main menu bar, navigate to GameObject | Create Empty.
- Rename the object MeMyselfEye.
- Ensure it has a reset transform (in its Inspector window's Transform pane, choose the gear icon in upper-right and select Reset).
- In the Hierarchy panel, drag the Main Camera object into MeMyselfEye so that it's a child object.
- With the Main Camera object selected, reset its transform values (in the Transform panel, in the upper-right section, click on the gear icon and select Reset).
- Then position yourself near the middle of the scene. Select MeMyselfEye again and set its Position (0, 0, -1.5).
- On some VR devices, the player height is determined by the device calibration and sensors, that is, your height in real life, so leave the Main Camera's Y-Position at 0.
- On other VR devices, especially ones with no positional tracking, you need to specify the camera height. Select the Main Camera (or more specifically, the game object that has the Camera component on it) and set its Position (0, 1.4, 0)
The Game view should show that we're inside the scene. If you recall the Ethan experiment that we did earlier, I picked a Y-position of 1.4 so that we'll be at about the eye level with Ethan.
Now, let's save this as a reusable prefabricated object, or prefab, in the Project panel, under Assets so that we can use it again in the other scenes in the other chapters of this book:
- In Project panel, under Assets, select the top-level Assets folder, right-click and navigate to Create | Folder. Rename the folder Prefabs.
- Drag the MeMyselfEye prefab into the Project panel, under the Assets/Prefabs folder to create a prefab.
Your hierarchy with the prefab is shown here:
Now we will continue the discussion on how to build your project, on a per-platform basis. Please skip to the topic appropriate for your setup.
If you want to try your projects on multiple platforms, say VIVE (Windows) and Daydream (Android), consider making separate prefabs for each target device, for example, MeMyselfEye-SteamVR, MeMyselfEye-GVR, and so on and then swap them in and out as needed.