Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Unity 5.x
Mastering Unity 5.x

Mastering Unity 5.x: Create amazing games with brilliant game play features using Unity 5.x

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

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

Mastering Unity 5.x

Chapter 2. Level Design and Structure

This chapter is about designing and building playable levels for Dead Keys. More accurately, Dead Keys consists of multiple levels, and our focus in this chapter will be on the creation of one of those levels in detail. Only one needs be considered because the level-creation process is merely repeated creatively, after creating the first level, to produce all remaining levels at increasing difficulty levels. By level, I mean a scene in Unity terms-a complete and integrated 3D world where the game evolves according to its internal rules and logic. We'll look in depth at using and reusing modular assets, such as environment meshes, to build interesting levels of any size needed; we'll also see lightmapping and lighting overall to enhance realism, as well as NavMesh generation for artificial intelligence and Occlusion Culling for rendering optimization, among other issues. By the end of this chapter, we'll have constructed an integrated...

Setting the scene with a skybox

Our game environment should be dark, creepy, and suspenseful. But, every new Unity scene is created with a default, procedural skybox representing a cheery daytime, exterior. This needs to be changed. A skybox is ultimately a cube with flipped normals that surround and encompass the environment. Its faces contain an environment texture which, when mapped correctly, appears seamlessly across the model, creating the look of a vast skyline surrounding the scene. The primary purpose of our skybox should be to set a base and ambient lighting. The most appropriate skybox for our usage, then, is a night skybox or, at least, a dark, stormy (and perhaps slightly alien) skybox. There are many ways in Unity to create a skybox. One method is to create a cube-map texture (six separate textures) inside the image-editing software that maps to the faces of a cube. Another method, available in Unity 5, is a procedural skybox. Using this, Unity generates a skybox from some...

Level building - modular construction sets

Now the fun begins, though logistically challenging, the process of level building. Our aim is to build a fun and interesting level. But this must be balanced against many factors, including level size, ease of navigation, variety, and more. Creating a level is challenging because misplaced or poorly designed elements stand out for their failings. They break the player's experience. Decisions about architecture and where to include straight sections, turns, jumps, ledges, props, and doors collectively influence the atmosphere and mood of a level. Here, we'll focus on the modular building method, piecing together an expansive level from reusable pieces, exploring reasons, and justifications for our choices along the way. However, let's first see the modular set in its entirety, that is, the complete collection of architectural meshes from which the level must be constructed.

Level building - modular construction sets

Modular set for level construction

Each mesh is a modular...

Level building - organization and structure

Let's start the level construction process. There are many ways to begin here, but it's a good idea from the outset to develop with a clean workflow in mind. By clean I mean an organized, structured, and easy-to-maintain workflow; one that remains maintainable for projects of many scales. First, delete any and all objects in the new scene, and then create a single empty GameObject named root by navigating to GameObject | Create Empty from the application menu. This object will be the top-most object in the hierarchy, from which everything else will be a child directly or indirectly.

Level building - organization and structure

Creating a root object for the scene

Next, create a new child object named env, which will contain all environment pieces. Make sure that both the root and env objects are positioned at the world origin at (0,0,0). I typically position the world floor at 0 on the y axis, making this the lowest point in the world. It is, of course, possible for objects...

Level design - tips and tricks

Don't underestimate the design challenges faced when building a level. Arranging mesh modules meaningfully and constructing a layout that encourages exploration and invites interest is challenging. Is a corridor too long or too bendy? Is a walkway too narrow or too wide? Should there be a prop (such as a chair or a desk) in the corner of a room? These types of questions, and others, matter! They're not the kinds of things that should be settled just by flipping a coin. Consider the following design tips and tricks; that is, some guiding principles intended to help you build more interesting levels faster and easier.

Objective and feedback

Always remember the player objective when designing-the goal to be reached by the player during gameplay. This may be reaching a specific location, defeating a specific enemy, achieving a financial target, or something else. Most players like to feel successful, like to feel like they're moving toward that goal...

Setting the scene with a skybox


Our game environment should be dark, creepy, and suspenseful. But, every new Unity scene is created with a default, procedural skybox representing a cheery daytime, exterior. This needs to be changed. A skybox is ultimately a cube with flipped normals that surround and encompass the environment. Its faces contain an environment texture which, when mapped correctly, appears seamlessly across the model, creating the look of a vast skyline surrounding the scene. The primary purpose of our skybox should be to set a base and ambient lighting. The most appropriate skybox for our usage, then, is a night skybox or, at least, a dark, stormy (and perhaps slightly alien) skybox. There are many ways in Unity to create a skybox. One method is to create a cube-map texture (six separate textures) inside the image-editing software that maps to the faces of a cube. Another method, available in Unity 5, is a procedural skybox. Using this, Unity generates a skybox from some...

Level building - modular construction sets


Now the fun begins, though logistically challenging, the process of level building. Our aim is to build a fun and interesting level. But this must be balanced against many factors, including level size, ease of navigation, variety, and more. Creating a level is challenging because misplaced or poorly designed elements stand out for their failings. They break the player's experience. Decisions about architecture and where to include straight sections, turns, jumps, ledges, props, and doors collectively influence the atmosphere and mood of a level. Here, we'll focus on the modular building method, piecing together an expansive level from reusable pieces, exploring reasons, and justifications for our choices along the way. However, let's first see the modular set in its entirety, that is, the complete collection of architectural meshes from which the level must be constructed.

Modular set for level construction

Each mesh is a modular piece (or module...

Level building - organization and structure


Let's start the level construction process. There are many ways to begin here, but it's a good idea from the outset to develop with a clean workflow in mind. By clean I mean an organized, structured, and easy-to-maintain workflow; one that remains maintainable for projects of many scales. First, delete any and all objects in the new scene, and then create a single empty GameObject named root by navigating to GameObject | Create Empty from the application menu. This object will be the top-most object in the hierarchy, from which everything else will be a child directly or indirectly.

Creating a root object for the scene

Next, create a new child object named env, which will contain all environment pieces. Make sure that both the root and env objects are positioned at the world origin at (0,0,0). I typically position the world floor at 0 on the y axis, making this the lowest point in the world. It is, of course, possible for objects to fall below...

Level design - tips and tricks


Don't underestimate the design challenges faced when building a level. Arranging mesh modules meaningfully and constructing a layout that encourages exploration and invites interest is challenging. Is a corridor too long or too bendy? Is a walkway too narrow or too wide? Should there be a prop (such as a chair or a desk) in the corner of a room? These types of questions, and others, matter! They're not the kinds of things that should be settled just by flipping a coin. Consider the following design tips and tricks; that is, some guiding principles intended to help you build more interesting levels faster and easier.

Objective and feedback

Always remember the player objective when designing-the goal to be reached by the player during gameplay. This may be reaching a specific location, defeating a specific enemy, achieving a financial target, or something else. Most players like to feel successful, like to feel like they're moving toward that goal. During gameplay...

Level lighting - preparation


Reaching this far you've now made a complete scene in terms of meshes representing the first level, composed from modular environment pieces (corridor sections). Presently, the level features no lighting, navigation meshes, music or audio, and Occlusion Data; but, we'll add these soon. Let's start with lighting. In Unity, there are three main lighting types or systems, which exist on a spectrum:

  • Baked lighting

  • Real-time lighting

  • Precomputed global illumination

These are discussed in detail further here.

Baked lighting

Baked lighting is the optimal lighting method, but it can only be used under specific circumstances. With Baked lighting, all lighting data (highlights, shadows, and so on) are precalculated and saved to a texture (lightmap). The lightmap is then applied to scene geometry using a second UV channel (Lightmap UVs), on top of their standard materials, using multiplicative blending. This makes geometry appear illuminated by scene lights. This approach...

Getting started with lightmapping


To start Baking Scene lighting, we'll first need to activate Lightmap UVs for the environment meshes and then position some lights in the scene where appropriate. To activate Lightmap UVs, select all environment meshes in the Project panel and enable Generate Lightmap UV from the object Inspector. Then click on Apply. This method is useful for generating a second UV channel when one doesn't already exist. This defines how lighting is baked to the lightmap texture. Unity applies an auto-unwrap projection using settings from the Advanced roll out. If, by contrast, your own meshes already have a custom, second channel, then you can use this channel instead for Lightmap UVs simply by disabling Generate Lightmap UVs.

Configuring Lightmap UVs

Note

For meshes with two UV channels, you can enable Swap UVs from the object Inspector to switch channel order, if needed. This makes the second channel the primary, and the first channel the secondary. The primary channel...

Baking lightmaps - resolution and size


Our scene now features marked static objects, complete with Lightmap UVs, and is ready for lightmapping. The default settings for all Unity scenes and projects is not compatible with a full lightmap setup as we require, and so we must access the lighting settings. To do this, display the Lighting window by navigating to Window | Lighting from the application menu. Once opened, dock the free-floating window into the object Inspector as a separate tab. This is convenient because we can view the lighting settings and inspect the Scene viewport side by side.

Accessing the Lighting window

First, let's disable all precomputed GI settings, by removing the check mark from the Precomputed Realtime GI rollout in the Lighting window. This completely deactivates real-time GI for the scene. In addition, specify the night time skybox (created earlier) for the Skybox field. This is important for establishing a base, ambient lighting pervading the scene, even in the...

Baking lightmaps - details


Having now established a resolution and Atlas Size, we should specify baking details to improve the quality and appearance of our lightmaps. To do this, enable Ambient Occlusion and tweak the Max Distance field until you get the volumetric effect desired. This requires rebaking. Ambient Occlusion is sometimes called Contact Shadows because it generates shadows where two or more solid bodies meet, such as the floor meeting the wall, or crevices and cracks. This creates a volume effect, enhancing the 3D-feel of a scene.

Enabling Ambient Occlusion

In addition, enable Final Gather. Set the Ray Count to 256. Final Gather reduces noise and improves the quality of lightmapping. Higher values result in smooth, higher quality output, at the expense of the calculation time.

Enabling Final Gather

Finally, you can increase the resolution of specific objects, if needed. We don't need this for DK, but if you have large, eye catching and very important objects in a scene (such...

Light Probes


The lightmap setup works well for the scene, but applies only to static objects; such as walls, floors, ceilings, and props. Animated and movable objects, such as NPCs, will by contrast continue to be illuminated by expensive dynamic lights, unless additional steps are taken. Let's take those now using Light Probes. They are special sampling objects, which should be positioned strategically around the scene to record an average of light color and intensity at that location. When multiple Light Probes exist, movable objects such as characters are illuminated by interpolated values taken from the nearest probes. Light Probes, therefore, record color and intensity, but they do not cast shadows. To get started with Light Probes, create a new game object to act as the parent of all probes. Navigate to GameObject | Create Empty from the application menu. Name this object LightProbes.

Creating an empty object for Light Probes

Next, add a Light Probe group component to the newly created...

Lighting FAQ


This section takes time out to explore lighting issues and problems that sometimes arise and common methods for resolving them. The issues listed here may not arise for the Dead Keys project specifically, but it's likely you'll encounter them somewhere, on some projects. Consequently, it's good to know how the issues are solved or at least avoided. This section takes a Question and Answer format:

  • Scene lighting appears wrong when opening a scene in the editor: This happens when Auto is enabled from the Lighting window. As the scene is opened, lighting is rebaked. This may take time or may fail entirely. The result is that scene lighting may not appear correct instantly when a scene is opened. You can resolve this by disabling auto baking from the Lighting window and then saving the scene to confirm the change. The next time the scene is opened, the existing baked data will be used instead.

Disabling Auto for baking

  • Scene lighting is baked, but appears messed up in the scene...

Navigation mesh


Now it's time to explore NPC intelligence and, specifically, path finding. We'll need our NPC zombies to move around the scene intelligently; that is, to move without bumping into walls, floors, doors, and other obstacles, and without taking the most complex routes to nearby destinations. Our zombies must cleverly navigate their way around the environment, whatever its arrangement, finding their way toward the player to engage in combat, as though they really had brains! To achieve this, a navigation mesh is required. This is a nonvisible mesh asset, generated by Unity, to approximate the scene floor, for both exterior and interior environments. More accurately, it represents the total walkable floor of the scene-the area over which NPCs may maneuver for travelling from point to point. To access the navigation mesh features, click on Window | Navigation from the application menu. This opens the Navigation mesh window, which can be docked into the object Inspector.

Accessing...

Occlusion Culling


Unity imposes no official limits on the size of your scene, and there's no established convention or industry-standard making recommendations about scene size. This is a decision largely in your hands. But there will certainly be a limit in a practical sense. The complexity of meshes, materials, and special effects combine together with the number of meshes and their spread to determine just how computationally expensive a scene is when presented to a camera with a specific frustum and field of view. Unity tries to make scene rendering easier on the computer by applying Frustum Culling automatically. That is, it silently deactivates (culls) objects outside the viewing volume (frustum) of the camera. As objects leave the frustum, Unity ceases to render them, and as they enter the volume Unity starts rendering them. This optimization works well in many cases, for objects that clearly enter and leave the Frustum.

Camera frustum defines the limits of what can be seen

Using...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Become a Unity master by creating a practical, in-depth game-development project with Unity
  • Use advanced C# scripting to unlock the complete potential of Unity 5
  • Use Version Control to Effectively Manage and Scale your workflow

Description

Mastering Unity 5.x is for developers wishing to optimize the features of Unity 5.x. With an in-depth focus on a practical project, learn all about Unity architecture and impressive animation techniques. With this book, produce fun games with confidence.

Who is this book for?

If you are a Unity developer who now wants to develop and deploy interesting games by leveraging the new features of Unity 5.x, then this is the book for you. Basic knowledge of C# programming is assumed.

What you will learn

  • Preparation and Asset-Configuring
  • Level Design and Structure
  • Player Controls - Movement
  • Player Controls – Typing & Health
  • Enemies and Artificial Intelligence
  • Project Management & Version Control
  • Persistent Data – Load and Save Game States
  • Performance, Optimization, Mobiles, and More

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 27, 2017
Length: 592 pages
Edition : 1st
Language : English
ISBN-13 : 9781785880742
Vendor :
Unity Technologies
Languages :
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 : Jan 27, 2017
Length: 592 pages
Edition : 1st
Language : English
ISBN-13 : 9781785880742
Vendor :
Unity Technologies
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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 €5 each
Feature tick icon Exclusive print discounts
€264.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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 115.97
Mastering Unity 5.x
€41.99
Getting Started with Unity 5.x 2D Game Development
€36.99
Mastering Unity 2D Game  Development
€36.99
Total 115.97 Stars icon

Table of Contents

8 Chapters
1. Preparation and Asset-Configuring Chevron down icon Chevron up icon
2. Level Design and Structure Chevron down icon Chevron up icon
3. Player Controls - Movement Chevron down icon Chevron up icon
4. Player Controls - Typing and Health Chevron down icon Chevron up icon
5. Enemies and Artificial Intelligence Chevron down icon Chevron up icon
6. Project Management and Version Control Chevron down icon Chevron up icon
7. Persistent Data - Load and Save Game States Chevron down icon Chevron up icon
8. Performance, Optimization, Mobiles, and More Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(1 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
MR B BYFORD May 19, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Not bad book if you want to make a very specific type of 3D game
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.