Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Getting to Know Unity

DZone's Guide to

Getting to Know Unity

Learn the basics of developing in Unity, one of the most popular platforms for high-quality, visually stunning games for mobile devices and other platforms.

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

This is an excerpt from the first chapter of Unity in Action, Second Edition. Save 37% with the code fcchunter.

How to Use Unity

Let’s jump into what the Unity interface looks like and how it operates (that is what you’re here for, isn’t it?). If you haven’t done it already, download the program from www.unity3d.com and install it on your computer (be sure to include “Example Project” if it’s unchecked in the installer). After you install it, launch Unity to start exploring the interface.

You probably want an example to look at; open the included example project. A new installation should open the example project automatically, but you can also select File > Open Project to open it manually. The example project is installed in the shared user directory, which is something like C:\Users\Public\Documents\Unity Projects\ on Windows, or Users/Shared/Unity/ on Mac OS. You may also need to open the example scene. Double-click the Car scene file (highlighted in figure 1; scene files have the Unity cube icon) found by going to SampleScenes/Scenes/ in the file browser at the bottom of the editor. You should see a screen similar to figure 1.

Image title

Figure 1: Parts of the interface in Unity.

The interface in Unity is split up into different sections: the Scene tab, the Game tab, the Toolbar, the Hierarchy tab, the Inspector, the Project tab, and the Console tab. Each section has a different purpose, but all are crucial for the game building lifecycle:

  • You can browse through all the files in the Project tab.
  • You can place objects in the 3D scene being viewed using the Scene tab.
  • The Toolbar has controls for working with the scene.
  • You can drag and drop object relationships in the Hierarchy tab.
  • The Inspector lists information about selected objects, including linked code.
  • You can test playing in Game view while watching error output in the Console tab.

This is the default layout in Unity; all of the various views are in tabs and can be moved around or resized, docking in different places on the screen. Later you can play around with customizing the layout, but for now the default layout is the best way to understand what all the views do.

Scene View, Game View, and the Toolbar

The most prominent part of the interface is the Scene view in the middle. This is where you can see what the game world looks like and move objects around. Mesh objects in the scene appear as, well, the mesh object (defined in a moment). You can also see a number of other objects in the scene, represented by various icons and colored lines: cameras, lights, audio sources, collision regions, and so forth. Note that the view you’re seeing here isn’t the same as the view in the running game—you’re able to look around the scene without being constrained to the game’s view.

A mesh object is a visual object in 3D space. Visuals in 3D are constructed out of lots of connected lines and shapes; hence the word mesh.

The Game view isn’t a separate part of the screen, but rather another tab located right next to Scene (look for tabs at the top left of views). A couple of places in the interface have multiple tabs like this; if you click a different tab, the view is replaced by the new active tab. When the game is running, what you see in this view is the game. It isn’t necessary to manually switch tabs every time you run the game, because the view automatically switches to Game when the game starts.

TIP: While the game is running, you can switch back to the Scene view, allowing you to inspect objects in the running scene. This capability is hugely useful for seeing what’s going on while the game is running and it’s a helpful debugging tool which isn’t available in most game engines.

Speaking of running the game, it’s as simple as hitting the Play button above the Scene view. That whole top section of the interface is referred to as the Toolbar, and Play is located right in the middle. Figure 2 breaks apart the full editor interface to show only the Toolbar at the top, as well as the Scene/Game tabs right underneath.

Image title

Figure 2: Editor screenshot cropped to show Toolbar, Scene, and Game.

At the left side of the Toolbar are buttons for scene navigation and transforming objects—how to look around the scene and how to move objects. I suggest you spend some time practicing looking around the scene and moving objects, because these are two of the most important activities you’ll do in Unity’s visual editor. The right side of the Toolbar is where you’ll find drop-down menus for layouts and layers. As mentioned earlier, the layout of Unity’s interface is flexible, and the Layouts menu allows you to switch between layouts. As for the Layers menu, it’s advanced functionality that you can ignore for now.

Using the Mouse and Keyboard

Scene navigation is primarily done using the mouse, along with a few modifier keys used to modify what the mouse does. The three main navigation maneuvers are Move, Orbit, and Zoom. The specific mouse movements for each are described in appendix A at the end of this book, because they vary depending on what mouse you’re using. The three different movements involve clicking-and-dragging while holding down some combination of Alt (or Option on Mac) and Ctrl. Spend a few minutes moving around in the scene to understand what Move, Orbit, and Zoom do.

TIP: Although Unity can be used with one- or two-button mice, I highly recommend getting a three-button mouse (and yes, a three-button mouse works fine on Mac OS X).

Transforming objects is done through three main maneuvers, and the three scene navigation moves are analogous to the three transforms: Translate, Rotate, and Scale (figure 3 demonstrates the transforms on a cube).

Image title

Figure 3: Applying the three transforms: Translate, Rotate, and Scale. (The lighter lines are the previous state of the object before it was transformed).

When you select an object in the scene, you can then move it around (the mathematically accurate technical term is translate), rotate the object, or scale how big it is. Relating back to scene navigation, Move is when you Translate the camera, Orbit is when you Rotate the camera, and Zoom is when you Scale the camera. Besides the buttons on the Toolbar, you can switch between these functions by pressing W, E, or R on the keyboard. When you activate a transform, you’ll notice a set of color-coded arrows or circles appears over the object in the scene; this is the Transform gizmo, and you can click-and-drag this gizmo to apply the transformation.

A fourth tool is next to the transform buttons. Called the Rect tool, it’s designed for use with 2D graphics. This one tool combines movement, rotation, and scaling. These operations have to be separate tools in 3D but are combined in 2D because there’s one less dimension to worry about. Unity has a host of other keyboard shortcuts for speeding up a variety of tasks. For now, let’s move on to the remaining sections of the interface!

The Hierarchy Tab and the Inspector

Looking at the sides of the screen, you’ll see the Hierarchy tab on the left and the Inspector on the right (see figure 4). Hierarchy is a list view with the name of every object in the scene listed, with the names nested together according to their hierarchy linkages in the scene. It’s a way of selecting objects by name instead of hunting them down and clicking them within Scene. The Hierarchy linkages group objects together, visually grouping them like folders and allowing you to move the entire group together.

Image title

Figure 4: Editor screenshot cropped to show the Hierarchy and Inspector tabs.

The Inspector shows you information about the currently selected object. Select an object and the Inspector is then filled with information about that object. The information shown is pretty much a list of components, and you can even attach or remove components from objects. All game objects have at least one component, Transform, and you’ll always see information about positioning and rotation in the Inspector. Objects often have several components listed here, including scripts attached to that object.

The Project and Console Tabs

At the bottom of the screen, you’ll see Project and Console (see figure 5). As with Scene and View, these aren’t two separate portions of the screen but rather tabs that you can switch between. Project shows all the assets (art, code, and so on) in the project. Specifically, on the left side of the view is a listing of the directories in the project; when you select a directory, the right side of the view shows the individual files in that directory. The directory listing in Project is similar to the list view in Hierarchy, but whereas Hierarchy shows objects in the scene, Project shows files that may not be contained within any specific scene (including scene files—when you save a scene, it shows up in Project!).

Image title

Figure 5: Editor screenshot cropped to show the Project and Console tabs.

TIP: Project view mirrors the Assets directory on disk, but you generally shouldn’t move or delete files directly by going to the Assets folder. If you do those things within the Project view, Unity keeps in sync with that folder.

The Console is the place where messages from the code show up. Some of these messages are debug output deliberately placed by you, but Unity also emits error messages if it encounters problems in the script you wrote.

That’s all for now! For more on game dev with Unity, download the free first chapter of Unity in Action, Second Edition and see this Slideshare presentation.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
game development ,unity ,mobile ,mobile app development ,mobile games

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}