Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Unity 3.x Game Development Essentials
Unity 3.x Game Development Essentials

Unity 3.x Game Development Essentials: If you have an idea for a game but lack the skills to create it, this book is the perfect introduction. There’s lots of handholding through all the essentials, culminating in the building of a full 3D game.

Arrow left icon
Profile Icon Will Goldstone
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (100 Ratings)
Paperback Dec 2011 488 pages 1st Edition
eBook
NZ$44.99 NZ$64.99
Paperback
NZ$80.99
Subscription
Free Trial
Arrow left icon
Profile Icon Will Goldstone
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (100 Ratings)
Paperback Dec 2011 488 pages 1st Edition
eBook
NZ$44.99 NZ$64.99
Paperback
NZ$80.99
Subscription
Free Trial
eBook
NZ$44.99 NZ$64.99
Paperback
NZ$80.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Unity 3.x Game Development Essentials

Chapter 1. Enter the Third Dimension

Before getting started with any 3D package, it is crucial to understand the environment you'll be working in. As Unity is primarily a 3D-based development tool, many concepts throughout this book will assume a certain level of understanding of 3D development and game engines. It is crucial that you equip yourself with an understanding of these concepts before diving into the practical elements of the rest of this book. As such, in this chapter, we'll make sure you're prepared by looking at some important 3D concepts before moving on to discuss the concepts and interface of Unity itself. You will learn about:

  • Coordinates and vectors

  • 3D shapes

  • Materials and textures

  • Rigidbody dynamics

  • Collision detection

  • GameObjects and Components

  • Assets and Scenes

  • Prefabs

  • Unity editor interface

Getting to grips with 3D


Let's take a look at the crucial elements of 3D worlds, and how Unity lets you develop games in three dimensions.

Coordinates

If you have worked with any 3D application before, you'll likely be familiar with the concept of the Z-axis . The Z-axis, in addition to the existing X for horizontal and Y for vertical, represents depth. In 3D applications, you'll see information on objects laid out in X, Y, Z format—this is known as the Cartesian coordinate method . Dimensions, rotational values, and positions in the 3D world can all be described in this way. In this book, as in other documentation of 3D, you'll see such information written with parenthesis, shown as follows:

(3, 5, 3)

This is mostly for neatness, and also due to the fact that in programming, these values must be written in this way. Regardless of their presentation, you can assume that any sets of three values separated by commas will be in X, Y, Z order.

In the following image, a cube is shown at location (3,5,3) in the 3D world, meaning it is 3 units from 0 in the X-axis, 5 up in the Y-axis, and 3 forward in the Z-axis:

Local space versus world space

A crucial concept to begin looking at is the difference between local space and world space. In any 3D package, the world you will work in is technically infinite, and it can be difficult to keep track of the location of objects within it. In every 3D world, there is a point of origin, often referred to as the 'origin' or 'world zero', as it is represented by the position (0,0,0).

All world positions of objects in 3D are relative to world zero. However, to make things simpler, we also use local space (also known as object space) to define object positions in relation to one another. These relationships are known as parent-child relationships. In Unity, parent-child relationships can be established easily by dragging one object onto another in the Hierarchy. This causes the dragged object to become a child, and its coordinates from then on are read in terms relative to the parent object. For example, if the child object is exactly at the same world position as the parent object, its position is said to be (0,0,0), even if the parent position is not at world zero.

Local space assumes that every object has its own zero point, which is the point from which its axes emerge. This is usually the center of the object, and by creating relationships between objects, we can compare their positions in relation to one another. Such relationships, known as parent-child relationships, mean that we can calculate distances from other objects using local space, with the parent object's position becoming the new zero point for any of its child objects.

This is especially important to bear in mind when working on art assets in 3D modelling tools, as you should always ensure that your models are created at 0,0,0 in the package that you are using. This is to ensure that when imported into Unity, their axes are read correctly.

We can illustrate this in 2D, as the same conventions will apply to 3D. In the following example:

  • The first diagram (i) shows two objects in world space. A large cube exists at coordinates(3,3), and a smaller one at coordinates (6,7).

  • In the second diagram (ii), the smaller cube has been made a child object of the larger cube. As such the smaller cube's coordinates are said to be (3,4), because its zero point is the world position of the parent.

Vectors

You'll also see 3D vectors described in Cartesian coordinates. Like their 2D counterparts, 3D vectors are simply lines drawn in the 3D world that have a direction and a length. Vectors can be moved in world space, but remain unchanged themselves. Vectors are useful in a game engine context, as they allow us to calculate distances, relative angles between objects, and the direction of objects.

Cameras

Cameras are essential in the 3D world, as they act as the viewport for the screen.

Cameras can be placed at any point in the world, animated, or attached to characters or objects as part of a game scenario. Many cameras can exist in a particular scene, but it is assumed that a single main camera will always render what the player sees. This is why Unity gives you a Main Camera object whenever you create a new scene.

Projection mode—3D versus 2D

The Projection mode of a camera states whether it renders in 3D (Perspective) or 2D (Orthographic). Ordinarily, cameras are set to Perspective Projection mode, and as such have a pyramid shaped Field of View (FOV). A Perspective mode camera renders in 3D and is the default Projection mode for a camera in Unity. Cameras can also be set to Orthographic Projection mode in order to render in 2D—these have a rectangular field of view. This can be used on a main camera to create complete 2D games or simply used as a secondary camera used to render Heads UpDisplay (HUD) elements such as a map or health bar.

In game engines, you'll notice that effects such as lighting, motion blurs, and other effects are applied to the camera to help with game simulation of a person's eye view of the world—you can even add a few cinematic effects that the human eye will never experience, such as lens flares when looking at the sun!

Most modern 3D games utilize multiple cameras to show parts of the game world that the character camera is not currently looking at—like a 'cutaway' in cinematic terms. Unity does this with ease by allowing many cameras in a single scene, which can be scripted to act as the main camera at any point during runtime. Multiple cameras can also be used in a game to control the rendering of particular 2D and 3D elements separately as part of the optimization process. For example, objects may be grouped in layers, and cameras may be assigned to render objects in particular layers. This gives us more control over individual renders of certain elements in the game.

Polygons, edges, vertices, and meshes

In constructing 3D shapes, all objects are ultimately made up of interconnected 2D shapes known as polygons. On importing models from a modeling application, Unity converts all polygons to polygon triangles. By combining many linked polygons, 3D modeling applications allow us to build complex shapes, known as meshes. Polygon triangles (also referred to as faces) are in turn made up of three connected edges. The locations at which these edges meet are known as points or vertices.

By knowing these locations, game engines are able to make calculations regarding the points of impact, known as collisions, when using complex collision detection with Mesh Colliders, such as in shooting games to detect the exact location at which a bullet has hit another object. In addition to building 3D shapes that are rendered visibly, mesh data can have many other uses. For example, it can be used to specify a shape for collision that is less detailed than a visible object, but roughly the same shape. This can help save performance as the physics engine needn't check a mesh in detail for collisions. This is seen in the following image from the Unity car tutorial, where the vehicle itself is more detailed than its collision mesh:

In the second image, you can see that the amount of detail in the mesh used for the collider is far less than the visible mesh itself:

In game projects, it is crucial for the developer to understand the importance of the polygon count. The polygon count is the total number of polygons, often in reference to models, but also in reference to props, or an entire game level (or in Unity terms, 'Scene'). The higher the number of polygons, the more work your computer must do to render the objects onscreen. This is why we've seen an increase in the level of detail from early 3D games to those of today. Simply compare the visual detail in a game such as id's Quake(1996) with the details seen in Epic's Gears Of War (2006) in just a decade. As a result of faster technology, game developers are now able to model 3D characters and worlds, for games that contain a much higher polygon count and resultant level of realism, and this trend will inevitably continue in the years to come. This said, as more platforms emerge such as mobile and online, games previously seen on dedicated consoles can now be played in a web browser thanks to Unity. As such, the hardware constraints are as important now as ever, as lower powered devices such as mobile phones and tablets are able to run 3D games. For this reason, when modeling any object to add to your game, you should consider polygonal detail, and where it is most required.

Materials, textures, and shaders

Materials are a common concept to all 3D applications, as they provide the means to set the visual appearance of a 3D model. From basic colors to reflective image-based surfaces, materials handle everything.

Let's start with a simple color and the option of using one or more images—known as textures. In a single material, the material works with the shader, which is a script in charge of the style of rendering. For example, in a reflective shader, the material will render reflections of surrounding objects, but maintain its color or the look of the image applied as its texture.

In Unity, the use of materials is easy. Any materials created in your 3D modeling package will be imported and recreated automatically by the engine and created as assets that are reusable. You can also create your own materials from scratch, assigning images as textures and selecting a shader from a large library that comes built-in. You may also write your own shader scripts or copy-paste those written by fellow developers in the Unity community, giving you more freedom for expansion beyond the included set.

When creating textures for a game in a graphics package such as Photoshop or GIMP, you must be aware of the resolution. Larger textures will give you the chance to add more detail to your textured models, but be more intensive to render. Game textures imported into Unity will be scaled to a power of 2 resolution. For example:

  • 64px x 64px

  • 128px x 128px

  • 256px x 256px

  • 512px x 512px

  • 1024px x 1024px

Creating textures of these sizes with content that matches at the edges will mean that they can be tiled successfully by Unity. You may also use textures scaled to values that are not powers of two, but mostly these are used for GUI elements as you will discover over the course of this book.

Rigidbody physics


For developers working with game engines, physics engines provide an accompanying way of simulating real-world responses for objects in games. In Unity, the game engine uses Nvidia's PhysX engine, a popular and highly accurate commercial physics engine.

In game engines, there is no assumption that an object should be affected by physics—firstly because it requires a lot of processing power, and secondly because there is simply no need to do so. For example, in a 3D driving game, it makes sense for the cars to be under the influence of the physics engine, but not the track or surrounding objects, such as trees, walls, and so on—they will remain static for the duration of the game. For this reason, when making games in Unity a Rigidbody physics component is given to any object that you wish to be under the control of the physics engine, and ideally any moving object, so that the physics engine is aware of the moving object, to save on performance.

Physics engines for games use the Rigidbody dynamics system of creating realistic motion. This simply means that instead of objects being static in the 3D world, they can have properties such as mass, gravity, velocity, and friction.

As the power of hardware and software increases, Rigidbody physics is becoming more widely applied in games, as it offers the potential for more varied and realistic simulation. We'll be utilizing rigid body dynamics as part of our prototype in this chapter and as part of the main game of the book in Chapter 7, Instantiation and Rigid Bodies.

Collision detection

More crucial in game engines than in 3D animation, collision detection is the way we analyze our 3D world for inter-object collisions. By giving an object a Collider component, we are effectively placing an invisible net around it. This net usually mimics its shape and is in charge of reporting any collisions with other colliders, making the game engine respond accordingly.

There are two main types of Collider in Unity—Primitives and Meshes. Primitive shapes in 3D terms are simple geometric objects such as Boxes, Spheres, and Capsules. Therefore, a primitive collider such as a Box collider in Unity has that shape, regardless of the visual shape of the 3D object it is applied to. Often, Primitive colliders are used because they are computationally cheaper or because there is no need for precision. A Mesh collider is more expensive as it can be based upon the shape of the 3D mesh it is applied to; therefore, the more complex the mesh, the more detailed and precise the collider will be, and more computationally expensive it will become. However, as shown in the Car tutorial example earlier, it is possible to assign a simpler mesh than that which is rendered, in order to create simpler and more efficient mesh colliders.

The following diagram illustrates the various types and subtypes of collider:

For example, in a ten-pin bowling game, a simple Sphere collider will surround the ball, while the pins themselves will have either a simple Capsule collider, or for a more realistic collision, employ a Mesh collider, as this will be shaped the same as the 3D mesh of the pin. On impact, the colliders of any affected objects will report to the physics engine, which will dictate their reaction, based on the direction of impact, speed, and other factors.

In this example, employing a Mesh collider to fit exactly to the shape of the pin model would be more accurate but is more expensive in processing terms. This simply means that it demands more processing power from the computer, the cost of which is reflected in slower performance, and hence the term expensive.

Essential Unity concepts


Unity makes the game production process simple by giving you a set of logical steps to build any conceivable game scenario. Renowned for being non-game-type specific, Unity offers you a blank canvas and a set of consistent procedures to let your imagination be the limit of your creativity. By establishing its use of the GameObject concept, you are able to break down parts of your game into easily manageable objects, which are made of many individual Component parts. By making individual objects within the game—introducing functionality to them with each component you add, you are able to infinitely expand your game in a logical progressive manner.

Component parts in turn have Variables—essentially properties of the component, or settings to control them with. By adjusting these variables, you'll have complete control over the effect that Component has on your object. The following diagram illustrates this:

In the following image we can see a Game Object with a Light Component, as seen in the Unity interface:

Now let's look at how this approach would be used in a simple gameplay context.

The Unity way—an example

If we wished to have a bouncing ball as part of a game, then we would begin with a sphere. This can quickly be created from the Unity menus, and will give you a new GameObject with a Sphere mesh (the 3D shape itself). Unity will automatically add a Renderer component to make it visible. Having created this, we can then add a Rigidbody component. A Rigidbody (Unity refers to most two-word phrases as a single word term) is a component which tells Unity to apply its physics engine to an object. With this comes properties such as mass, gravity, drag, and also the ability to apply forces to the object, either when the player commands it or simply when it collides with another object.

Our sphere will now fall to the ground when the game runs, but how do we make it bounce? This is simple! The collider component has a variable called Physic Material—this is a setting for the physics engine, defining how it will react to other objects' surfaces. Here we can select Bouncy—a ready-made Physic material provided by Unity as part of an importable package and voila! Our bouncing ball is complete in only a few clicks.

This streamlined approach for the most basic of tasks, such as the previous example, seems pedestrian at first. However, you'll soon find that by applying this approach to more complex tasks, they become very simple to achieve. Here is an overview of some further key Unity concepts you'll need to know as you get started.

Assets

These are the building blocks of all Unity projects. From textures in the form of image files, through 3D models for meshes, and sound files for effects, Unity refers to the files you'll use to create your game as assets. This is why in any Unity project folder all files used are stored in a child folder named Assets. This Assets folder is mirrored in the Project panel of the Unity interface; see The interface section in this chapter.

Scenes

In Unity, you should think of scenes as individual levels, or areas of game content—though some developers create entire games in a single scene, such as, puzzle games, by dynamically loading content through code. By constructing your game with many scenes, you'll be able to distribute loading times and test different parts of your game individually. New scenes are often used separately to a game scene you may be working on, in order to prototype or test a piece of potential gameplay.

Any currently open scene is what you are working on, as no two scenes can be worked on simultaneously. Scenes can be manipulated and constructed by using the Hierarchy and Scene views.

GameObjects

Any active object in the currently open scene is called a GameObject . Certain assets taken from the Project panel such as models and prefabs become game objects when placed (or 'instantiated') into the current scene. Other objects such as particle systems and primitives can be placed into the scene by using the Create button on the Hierarchy or by using the GameObject menu at the top of the interface. All GameObjects contain at least one component to begin with, that is, the Transform component. Transform simply tells the Unity engine the position, rotation, and scale of an object—all described in X, Y, Z coordinate (or in the case of scale, dimensional) order. In turn, the component can then be addressed in scripting in order to set an object's position, rotation, or scale. From this initial component, you will build upon GameObjects with further components, adding required functionality to build every part of any game scenario you can imagine.

In the following image, you can see the most basic form of a Game Object, as shown in the Inspector panel:

GameObjects can also be nested in the Hierarchy, in order to create the parent-child relationships mentioned previously.

Components

Components come in various forms. They can be for creating behavior, defining appearance, and influencing other aspects of an object's function in the game. By attaching components to an object, you can immediately apply new parts of the game engine to your object. Common components of game production come built-in with Unity, such as the Rigidbody component mentioned earlier, down to simpler elements such as lights, cameras, particle emitters, and more. To build further interactive elements of the game, you'll write scripts, which are also treated as components in Unity. Try to think of a script as something that extends or modifies the existing functionality available in Unity or creates behavior with the Unity scripting classes provided.

Scripts

While being considered by Unity to be components, scripts are an essential part of game production, and deserve a mention as a key concept. In this book, we will write our scripts in both C Sharp (More often written as 'C#') and Javascript. You should also be aware that Unity offers you the opportunity to write in Boo (a derivative of the Python language).We have chosen to primarily focus on C# and Javascript as these are the main two languages used by Unity developers, and Boo is not supported for scripting on mobile devices; for this reason it is not advised to begin learning Unity scripting with Boo.

Unity does not require you to learn how the coding of its own engine works or how to modify it, but you will be utilizing scripting in almost every game scenario you develop. The beauty of using Unity scripting is that any script you write for your game will be straightforward enough after a few examples, as Unity has its own built-in Behavior class called Monobehavioura set of scripting instructions for you to call upon. For many new developers, getting to grips with scripting can be a daunting prospect, and one that threatens to put off new Unity users who are more accustomed to design. If this is your first attempt at getting into game development, or you have no experience in writing code, do not worry. We will introduce scripting one step at a time, with a mind to showing you not only the importance, but also the power of effective scripting for your Unity games.

To write scripts, you'll use Unity's standalone script editor, Monodevelop. This separate application can be found in the Unity application folder on your PC or Mac and will be launched any time you edit a new script or an existing one. Amending and saving scripts in the script editor will immediately update the script in Unity as soon as you switch back to Unity. You may also designate your own script editor in the Unity preferences if you wish to, such as Visual Studio. Monodevelop is recommended however, as it offers auto-completion of code as you type and is natively developed and updated by Unity Technologies.

Prefabs

Unity's development approach hinges around the GameObject concept, but it also has a clever way to store objects as assets to be reused in different parts of your game, and then instantiated (also known as 'spawning' or 'cloning') at any time. By creating complex objects with various components and settings, you'll be effectively building a template for something you may want to spawn multiple instances of (hence 'instantiate'), with each instance then being individually modifiable.

Consider a crate as an example—you may have given the object in the game a mass, and written scripted behaviors for its destruction, and chances are you'll want to use this object more than once in a game, and perhaps even in games other than the one it was designed for.

Prefabs allow you to store the object, complete with components and current configuration. Comparable to the MovieClip concept in Adobe Flash, think of prefabs simply as empty containers that you can fill with objects to form a data template you'll likely recycle.

The interface


The Unity interface, like many other working environments, has a customizable layout. Consisting of several dockable spaces, you can pick which parts of the interface appear where. Let's take a look at a typical Unity layout:

This layout can be achieved by going to Window | Layouts | 2 by 3 in Unity.

As the previous image demonstrates (Mac version shown), there are five different panels or views you'll be dealing with, which are as follows:

Scene [1]—where the game is constructed.

Game [2]—the preview window, active only in play mode.

Hierarchy [3]—a list of GameObjects in the scene.

Project [4]—a list of your project's assets; acts as a library.

Inspector [5]—settings for currently selected asset/object/setting.

The Scene view and Hierarchy

The Scene view is where you will build the entirety of your game project in Unity. This window offers a perspective (full 3D) view, which is switchable to orthographic (top-down, side-on, and front-on) views. When working in one of the orthographic views, rotating the view will display the scene isometrically. The Scene view acts as a fully rendered 'Editor' view of the game world you build. Dragging an asset to this window (or the Hierarchy) will create an instance of it as a GameObject in the Scene.

The Scene view is tied to the Hierarchy, which lists all GameObjects in the currently open scene in ascending alphabetical order.

Control tools

The Scene window is also accompanied by four useful control tools, as shown in the following image:

Accessible from the keyboard using keys Q, W, E, and R, these keys perform the following operations:

  • The Hand tool [Q]: This tool allows navigation of the Scene window. By itself, it allows you to drag around in the Scene window with the left mouse button to pan your view. Holding down Alt with this tool selected will allow you left click to orbit your view around a central point you are looking at, and holding the Alt key with right click will allow you to zoom, as will scrolling the mouse wheel. Holding the Shift key down also will speed up both of these functions.

  • The Translate tool [W]: This is your active selection tool. As you can completely interact with the Scene window, selecting objects either in the Hierarchy or Scene means you'll be able to drag the object's axis handle in order to reposition them.

  • The Rotate tool[E]: This works in the same way as Translate, using visual 'handles' to allow you to rotate your object around each axis.

  • The Scale tool [R]: Again, this tool works as the Translate and Rotate tools do. It adjusts the size or scale of an object using visual handles.

Having selected objects in either the Scene or Hierarchy, they immediately get selected in both. Selection of objects in this way will also show the properties of the object in the Inspector. Given that you may not be able to see an object you've selected in the Hierarchy in the Scene window, Unity also provides the use of the F key, to focus your Scene view on that object. Simply select an object from the Hierarchy, hover your mouse cursor over the Scene window, and press F. You can also achieve this by double-clicking the name of a game object in the Hierarchy.

Flythrough Scene navigation

To move around your Scene view using the mouse and keys you can use Flythrough mode. Simply hold down the right mouse button and drag to look around in first-person style, then use W, A, S and D to move and Q and E to descend and ascend (respectively).

Control bar

In addition to the control tools, there is also a bar of additional options to help you work with your Unity scenes, which is shown as follows:

Known as the Scene View Control Bar, this bar allows you to adjust (left to right):

  • Draw mode (default is 'Textured')

  • Render mode (default is 'RGB')

  • Toggle scene lighting

  • Toggle overlays—shows and hides GUI elements and Skyboxes and toggles the 3D grid

  • Toggle audition mode—previews audio sources in the current scene

  • Gizmos—use this pop-out menu to show or hide Gizmos, the 2D icons of cameras, lights, and other components shown in the scene.

Search box

While the Scene view is intrinsically linked with the Hierarchy, often you may need to locate an item or type of item in the Scene view itself by searching. Simply type the name or data type (in other words, an attached component) of an object into the search, and the Scene view will grey out other objects in order to highlight the item you have searched for. This becomes very useful when dealing with more complex scenes, and should be used in conjunction with F on the keyboard to focus on the highlighted object in the Scene window itself.

Create button

As many of the game assets you'll use in Unity will be created by the editor itself, the Hierarchy has a Create button that allows you to create objects that are also located within the top GameObject menu. Similar to the Create button on the Project panel, this drop-down menu creates items and immediately selects them so that you may rename or begin working with them in the Scene or Inspector.

The Inspector

Think of the Inspector as your personal toolkit to adjust every element of any GameObject or asset in your project. Much like the Property Inspector concept utilized by Adobe in Flash and Dreamweaver, this is a context-sensitive window. All this means is that whatever you select, the Inspector will change to show its relevant properties—it is sensitive to the context in which you are working.

The Inspector will show every component part of anything you select, and allow you to adjust the variables of these components, using simple form elements such as text input boxes, slider scales, buttons, and drop-down menus. Many of these variables are tied into Unity's drag-and-drop system, which means that rather than selecting from a drop-down menu, if it is more convenient, you can drag-and-drop to choose settings or assign properties.

This window is not only for inspecting objects. It will also change to show the various options for your project when choosing them from the Edit menu, as it acts as an ideal space to show you preferences—changing back to showing component properties as soon as you reselect an object or asset.

In this image, the Inspector is showing properties for a target object in the game. The object itself features two components—Transform and Animation. The Inspector will allow you to make changes to settings in either of them. Also note that in order to temporarily disable any component at any time, which will become very useful for testing and experimentation—you can simply deselect the checkbox to the left of the component's name. Likewise, if you wish to switch off an entire object at a time, then you may deselect the checkbox next to its name at the top of the Inspector window.

The Project window

The Project window is a direct view of the Assets folder of your project. Every Unity project is made up of a parent folder, containing three subfolders—Assets, Library, and while the Unity Editor is running, a Temp folder. Placing assets into the Assets folder means you'll immediately be able to see them in the Project window, and they'll also be automatically imported into your Unity project. Likewise, changing any asset located in the Assets folder, and resaving it from a third-party application, such as Photoshop, will cause Unity to reimport the asset, reflecting your changes immediately in your project and any active scenes that use that particular asset.

Note

Asset management

It is important to remember that you should only alter asset locations and names using the Project window—using Finder (Mac) or Windows Explorer (PC) to do so may break connections in your Unity project. Therefore, to relocate or rename objects in your Assets folder, use Unity's Project window instead of your operating system.

The Project window, like the Hierarchy, is accompanied by a Create button. This allows the creation of any assets that can be made within Unity, for example, scripts, prefabs, and materials.

The Game view

The Game view is invoked by pressing the Play button and acts as a realistic test of your game. It also has settings for screen ratio, which will come in handy when testing how much of the player's view will be restricted in certain ratios, such as 4:3 (as opposed to wide) screen resolutions. Having pressed Play, it is crucial that you bear in mind the following advice:

Note

Play mode—testing only!

In play mode, the adjustments you make to any parts of your game scene are merely temporary. It is meant as a testing mode only, and when you press Play again to stop the game, all changes made to active GameObjects during play mode will be undone. This can often trip up new users, so don't forget about it!

The Game view can also be set to Maximize when you invoke play mode, giving you a better view of the game at nearly fullscreen—the window expands to fill the interface. It is worth noting that you can expand any part of the interface in this way, simply by hovering over the part you wish to expand and pressing the Space bar.

In addition to using Play to preview your game, the live game mode can also be paused by pressing the Pause button at the top of the interface, and play can be advanced a frame at a time using the third button, Advance Frame, next to Pause. This is useful when Debugging—the process of finding and solving problems or 'bugs' with your game development.

Summary


Here we have looked at the key concepts you will need to understand and complete the exercises in this book. However, 3D is a detailed discipline that you will continue to learn not only with Unity, but in other areas also. With this in mind, you are recommended to continue to read more on the topics discussed in this chapter, in order to supplement your study of 3D development. Each individual piece of software you encounter will have its own dedicated tutorials and resources dedicated to learning it. If you wish to learn 3D artwork to complement your work in Unity, you are recommended to familiarize yourself with your chosen package, after researching the list of tools that work with the Unity pipeline and choosing which one suits you the best.

Now that we've taken a brief look at 3D concepts and the processes used by Unity to create games, we'll begin by completing a simple exercise before getting started on the larger game element of this book.

In the following chapter, we'll begin with a short exercise in which you will prototype a simple game mechanic using Primitive shapes generated by the engine itself, and some basic coding to get you started in C Sharp (C#)/ Javascript. It is important to kick-start your Unity learning with a simple example using primitives, as you will often find yourself prototypinggame ideas in this manner once you feel more comfortable in using Unity.

After this, we'll move on to the larger exercise of the book, looking at game environments and getting to grips with the terrain editor. With a physical height painting approach, the terrain editor is an easy to use starting point for any game with an outdoor environment. We'll use this to build an island, and in the ensuing chapters we'll add features to the island to create a mini-game, in which the user must light a campfire by retrieving matches from a locked outpost. Let's get started!

Left arrow icon Right arrow icon

Key benefits

  • Kick start your game development, and build ready-to-play 3D games with ease.
  • Understand key concepts in game design including scripting, physics, instantiation, particle effects, and more.
  • Test & optimize your game to perfection with essential tips-and-tricks.
  • Written in clear, plain English, this book takes you from a simple prototype through to a complete 3D game with concepts you‚Äôll reuse throughout your new career as a game developer.
  • Learn game development in Unity version 3 and above, and learn scripting in either C# or JavaScript

Description

Game Engines such as Unity are the power-tools behind the games we know and love. Unity is one of the most widely-used and best loved packages for game development and is used by everyone, from hobbyists to large studios, to create games and interactive experiences for the web, desktop, mobile, and console. With Unity’s intuitive, easy to learn toolset and this book – it’s never been easier to become a game developer. Taking a practical approach, this book will introduce you to the concepts of developing 3D games, before getting to grips with development in Unity itself – prototyping a simple scenario, and then creating a larger game. From creating 3D worlds to scripting and creating game mechanics you will learn everything you’ll need to get started with game development. This book is designed to cover a set of easy-to-follow examples, which culminate in the production of a First Person 3D game, complete with an interactive island environment. All of the concepts taught in this book are applicable to other types of game, however, by introducing common concepts of game and 3D production, you'll explore Unity to make a character interact with the game world, and build puzzles for the player to solve, in order to complete the game. At the end of the book, you will have a fully working 3D game and all the skills required to extend the game further, giving your end-user, the player, the best experience possible. Soon you will be creating your own 3D games with ease!

Who is this book for?

If you’re a designer or animator who wishes to take their first steps into game development or prototyping, or if you’ve simply spent many hours sitting in front of video games, with ideas bubbling away in the back of your mind, Unity and this book should be your starting point. No prior knowledge of game production is required, inviting you to simply bring with you a passion for making great games.

What you will learn

  • An understanding of the Unity 3D Engine and game development
  • Write code for game development in either C# or JavaScript
  • Build a 3D island and set of mini-games for your players
  • Incorporate terrains and externally produced 3D models to get your game environment up and running
  • Create player character interactions
  • Combine scripting and animation to transform your static objects into dynamic interactive game elements
  • Add realistic effects to your games by using particle systems
  • Create a stylish and efficient menu, and animate other interface elements
  • Use Lightmapping to make your game environments look more professional
  • Deploy your game to the web and desktop and share it with the wider world for testing and feedback.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 20, 2011
Length: 488 pages
Edition : 1st
Language : English
ISBN-13 : 9781849691444
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 20, 2011
Length: 488 pages
Edition : 1st
Language : English
ISBN-13 : 9781849691444
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total NZ$ 161.98
Unity 3.x Game Development Essentials
NZ$80.99
Learning C# by Developing Games with Unity 3D Beginner's Guide
NZ$80.99
Total NZ$ 161.98 Stars icon

Table of Contents

13 Chapters
Enter the Third Dimension Chevron down icon Chevron up icon
Prototyping and Scripting Basics Chevron down icon Chevron up icon
Creating the Environment Chevron down icon Chevron up icon
Player Characters and Further Scripting Chevron down icon Chevron up icon
Interactions Chevron down icon Chevron up icon
Collection, Inventory, and HUD Chevron down icon Chevron up icon
Instantiation and Rigidbodies Chevron down icon Chevron up icon
Particle Systems Chevron down icon Chevron up icon
Designing Menus Chevron down icon Chevron up icon
Animation Basics Chevron down icon Chevron up icon
Performance Tweaks and Finishing Touches Chevron down icon Chevron up icon
Building and Sharing Chevron down icon Chevron up icon
Testing and Further Study Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(100 Ratings)
5 star 64%
4 star 27%
3 star 8%
2 star 1%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Michael Mar 26, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you're new to Unity this book is perfect. Very clear instructions. The book teaches you on how to build a game and every chapter takes you to adding new stuff towards completion of the game. I have c# background but the book covers c# and javascript so it's all good. I hope he releases another book for 2013. The author even responds to my emails despite his busy schedule. :-)
Amazon Verified review Amazon
Lelle Nov 03, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good guide to open the nature of the program. Highly recommended, value for the price. Very easy to understand even the most complicated commands/codes of the program.
Amazon Verified review Amazon
Rodrigo Mamao Apr 03, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Unity 3.x Game Development Essentials remains true to the style of the first version but with improved explanations on main topics and updated information about the features added to Unity since then.It is a good book for those who wish a step by step introduction to Unity, from prototyping to optimization. It uses both C# and Javascript, so you can follow the one you feel more comfortable with. Since Unit is really an environment and not a language, information about the user interface is helpful when you are new to it. The book use screenshots where it is important, without overusing it. An additional bonus goes to small tip boxes along the text, with helpful insights. Details like this make all the difference.
Amazon Verified review Amazon
Eclectus Nov 08, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written, good structure, and available on kindle. All code examples available in C# which is good (javascript is there too, for all of them). Have not found any mistakes in the book.
Amazon Verified review Amazon
William Smith Jul 11, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This was a great intro to Unity. Project built throughout had you using much of the tool and explaining multiple ways of accomplishing tasks. Also appreciated author taking the time to go through 2-3 ways of doing something and then showing why one is better than the other. After reading I feel like I can better understand how to use the tool to accomplish what I want and can now get much more out of online tutorials or other books on game development.Appreciated that Unity 4.0 package was available on authors web site.Using C# I did not find any errors with code in book (js looks like it has a few via the notes on authors site). When something did go wrong it was only because I missed a step or did not set something correctly. Also got Kindle edition and read on second computer, no issues with fonts/colors/etc...Will you be building awesome games after reading? Of course not, but what it will do is get you comfortable with a lot of the tools abilities and give you a basic level of knowledge about them. Would I recommend this to anyone interested in getting started with Unity? Absolutely.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.