Getting started with Unity
If you don't have the Unity 3D game engine application installed on your PC yet, do that now! The fully-featured Personal Edition is free and runs on both Windows and Mac. To get Unity, go to https://unity3d.com/get-unity/, select the version that you want, click on Download Installer, and continue following the instructions. This book assumes version 5.1 of Unity.
For you beginners out there, we're going to take this first section nice and slow, with more hand-holding than what you'll get later on in the book. Furthermore, even if you already know Unity and have developed your own games, it may be worthwhile revisiting the fundamental concepts, since the rules sometimes are different when designing for virtual reality.
Starting a new Unity project
Create a new Unity project named VR_is_Awesome
, or whatever you'd like.
To create a new Unity project, launch Unity from your operating system, and the Open dialog box will appear. From this dialog box, select New Project, which opens a New project dialog box, as shown in the following screenshot:
Fill in the name of your project and verify that the folder location is what you want. Ensure that 3D is selected (on the lower left). There is no need to select any extra asset packages at this time, as we'll bring them in later if we need them. Click on Create project.
The Unity editor
Your new project opens in the Unity editor, as shown in the following screenshot (where I arranged the window panels in a custom layout to facilitate this discussion and highlighted a couple of panels):
The Unity editor consists of a number of non-overlapping windows, or panels, which may be subdivided into panes. Here's a brief explanation of each panel that is shown in the preceding layout image (your layout may be different):
- The Scene panel on the upper left-hand side (highlighted) is where you can visually compose the 3D space of the current scene, including the placement of objects.
- Below the Scene panel (lower left-hand side) is the Game view, which shows the actual game camera view (presently, it is empty with an ambient sky). When in Play Mode, your game runs in this panel.
- In the center are the Hierarchy, Project, and Console panels (from the top to the bottom) respectively. The Hierarchy panel provides a tree view of all the objects in the current scene.
- The Project panel contains all the reusable resources for the project, including the ones imported as well as those that you'll create along the way.
- The Console panel shows messages from Unity, including warnings and errors from code scripts.
- On the right-hand side is the Inspector panel (highlighted), which contains the properties of the currently selected object. (Objects are selected by clicking on them in the Scene, Hierarchy, or the Project panel). The Inspector panel has separate panes for each component of the object.
- At the top is the main menu bar (on a Mac, this will be at the top of your screen, not at the top of the Unity window). There's a toolbar area with various controls that we'll use later on, including the play (triangle icon) button that starts Play Mode.
From the main menu bar Window menu, you can open additional panels, as needed. The editor's user interface is configurable. Each panel can be rearranged, resized, and tabbed by grabbing one of the panel tabs and dragging it. Go ahead, try it! On the upper right-hand side is a Layout selector that lets you either choose between various default layouts, or save your own preferences.
The default world space
A default empty Unity scene consists of a Main Camera component and a single Directional Light component, as listed in the Hierarchy panel and depicted in the Scene panel. The Scene panel also shows a perspective of an infinite reference ground plane grid, like a piece of graph paper with nothing on it yet. The grid spans across the x (red) and z (blue) axes. The y-axis (green) is up.
The Inspector panel shows the details of the currently selected item: Select the Directional Light with your mouse, either from the Hierarchy list or within the scene itself, and look at the Inspector panel for each of the properties and components associated with the object, including its transform. An object's transform specifies its position, rotation, and scale in the 3D world space. For example, a (0, 3, 0) position is 3 units above (Y direction) the center of the ground plane (X = 0, Z = 0). A rotation of (50, 330, 0) means that it's rotated 50 degrees around the x-axis and 330 degrees around the y-axis. As you'll see, you can change an object's transforms numerically here or directly with the mouse in the Scene panel.
Similarly, if you click on the Main Camera, it may be located at the (0, 1, -10) position with no rotation. That is, it's pointed straight ahead, towards the positive Z direction.
When you select the Main Camera, as shown in the preceding editor screenshot, a Camera Preview inset is added to the Scene panel, which shows the view that the camera presently sees. (If the Game tab is open, you'll see the same view there too). Presently, the view is empty and the reference grid does not get rendered, but a foggy horizon is discernible, with the grey ground plane below and the blue default ambient Skybox above.