Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Unity 2017 Game Development with C#
Mastering Unity 2017 Game Development with C#

Mastering Unity 2017 Game Development with C#: Create professional games with solid gameplay features and professional-grade workflow , Second Edition

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. €18.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 2017 Game Development with C#

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 in this chapter, our focus 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 the 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...

Setting the scene with a skybox

Our game environment should be dark, creepy, and suspenseful. However, 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 a flipped normal 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 to create a skybox in Unity. One method is to create a cube-map texture (six separate textures) inside the image-editing software that maps to the faces of...

Level building - Modular construction sets

Now the fun begins, though it's 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...

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 topmost 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. Ensure that both the root and env objects are positioned at the world origin at (0,0,0). I typically position the world floor...

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 question, and others, matter! They're not the kinds of thing that should be settled just by flipping a coin. Consider the following design tips and tricks, which are some guiding principles intended to help you build more interesting levels more quickly and easily.

Objective and feedback

Always remember the player objective when...

Level lighting - Preparation

Reaching this far, you've now made a complete scene in terms of meshes representing the first level, composed of 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 further detail 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...

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 autounwrap projection using settings from the Advanced roll out. If, by contrast, your own meshes already have a custom, second channel, and you can use this channel instead for Lightmap UVs simply by disabling Generate Lightmap UVs:

Configuring Lightmap UVs
For meshes with two UV channels, you can enable Swap UVs from the object Inspector to switch 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 | Settings 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 Realtime Global Illumination checkbox in the Realtime Lighting rollout. This completely deactivates real-time GI for the scene. In addition, specify the night...

Baking lightmaps - Details

Having now established a resolution and Lightmap 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...

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 continue to be illuminated by expensive dynamic lights, in contrast, unless additional steps are taken; let's take those now using Light Probes. They are special sampling objects, that 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, and name this...

Lighting FAQ

This section takes time out to explore lighting issues and problems that sometimes arise and common methods to solve them. The issues listed here may not arise for the Dead Keys project specifically, but it's likely that 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 Generate is enabled from the Lighting window. As the scene is opened, lighting is rebaked. This may take time or may fail entirely for various reasons. The result is that scene lighting may not appear correct instantly when a scene is opened. You can resolve this by disabling auto generate from the Lighting window and then saving the scene to confirm the change. The next...

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 an invisible 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 to travel from point to point. To access the navigation mesh features, click on Window | Navigation from...

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 combined with the number of meshes and their spread determines 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...

Creating a player camera

The camera object is, in many ways, the most important in any scene, because without the presence of at least one camera, the scene can't be rendered at all. Dead Keys will eventually feature multiple cameras, each with a dedicated purpose. However, let's focus on the main camera, that is, the player perspective in the scene now. For first person games, you can create a camera easily by dragging and dropping a First Person Controller from the Project panel into the scene, from the Characters asset package. However, for Dead Keys, we don't need that; our camera path is fixed as it moves through the level and the user doesn't need free-look controls with the mouse or W A S D keys. Consequently, we'll create a custom camera from the ground upwards.

Let's start by creating a camera object by navigating to GameObject | Camera from...

Particle systems

Particle systems are great for creating effects such as rain, snow, steam, sparkles, hordes of birds, footprints, armies of ants, and more. Unity ships with preconfigured particle systems ready to use, and it lets you create your own from scratch. Here, we'll use some premade systems that can be added easily to the scene, for drama and tension. To access the premade systems, import the ParticleSystem package into the project. Choose Assets | Import Package | ParticleSystems from the application menu if you've not imported the package already. From the Import dialog that appears, accept the default settings and click on the Import button:

Importing Unity particle systems

Once imported, you can access all premade particle systems via the Project panel, through the Standard Assets | ParticleSystems | Prefabs folder:

Access ParticleSystem packages

For...

Music and audio

To complete basic level configuration and structure, let's add music, specifically, the main background music that should play continuously throughout the level. In the last chapter, we imported audio assets, both music and sound effects, and configured these optimally. As discussed earlier, it is most important that music is configured for Streaming as the Load Type, and the Compression Format should be set to Vorbis. This ensures that Unity doesn't load the complete track into memory as it would do with sound and audio. Loading complete music tracks will be performance prohibitive, especially for mobile devices and legacy hardware:

Configuring music audio

In addition to importing music assets, let's create an Audio Mixer asset. This is optional in theory, as Unity can play audio without a mixer. However, mixers give you more control over different...

Summary

Congratulations! You've now created the first level of Dead Keys. Of course, more will be added, but let's first focus on creating one functional level, whose behaviors may be easily recycled to produce more levels, as needed. This chapter focused on many level design issues, both practical and theoretical. Specifically, we explored level design tips and tricks--methods for producing levels more simply and conveniently. In addition, we examined the modular building technique, alongside more advanced tools such as lightmapping, navigation meshes, and Occlusion Culling. In the next chapter, we'll examine how to take the first person camera and build player functionality using animation and scripting.

Left arrow icon Right arrow icon

Key benefits

  • Create professional grade games with realistic animation and graphics, particle systems and game physics with Unity 2017
  • Unleash the power of C# scripting to create intelligent game AI and professional grade game workflows.
  • Create immersive VR games using the latest Unity 2017 VR SDK.

Description

Do you want to make the leap from being an everyday Unity developer to being a pro game developer? Then look no further! This book is your one-stop solution to creating mesmerizing games with lifelike features and amazing gameplay. This book focuses in some detail on a practical project with Unity, building a first-person game with many features. You'll delve into the architecture of a Unity game, creating expansive worlds, interesting render effects, and other features to make your games special. You will create individual game components, use efficient animation techniques, and implement collision and physics effectively. Specifically, we'll explore optimal techniques for importing game assets, such as meshes and textures; tips and tricks for effective level design; how to animate and script NPCs; how to configure and deploy to mobile devices; how to prepare for VR development; how to work with version control; and more. By the end of this book, you'll have developed sufficient competency in Unity development to 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 2017, then this is the book for you. Basic knowledge of C# programming is assumed.

What you will learn

  • Explore hands-on tasks and real-world scenarios to make a Unity horror adventure game
  • Create enemy characters that act intelligently and make reasoned decisions
  • Use data files to save and restore game data in a way that is platform-agnostic
  • Get started with VR development
  • Use navigation meshes, occlusion culling, and Profiler tools
  • Work confidently with GameObjects, rotations, and transformations
  • Understand specific gameplay features such as AI enemies, inventory systems, and level design

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 30, 2017
Length: 568 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788479837
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. €18.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 : Oct 30, 2017
Length: 568 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788479837
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 2017 Game Development with C#
€41.99
Unity 2017 Mobile Game Development
€36.99
Unity 2017 Game Optimization
€36.99
Total 115.97 Stars icon

Table of Contents

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

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5
(2 Ratings)
5 star 0%
4 star 50%
3 star 0%
2 star 0%
1 star 50%
Wirv Feb 11, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
per un libro chiamato Mastering unity game development, ci si aspetta qualcosa di avanzato e che sia indirizzato a specializzarsi o che tratti di un progetto più generico o verso un tipo di titolo più complesso, invece questo libro è più adatto per un genere di nicchia quale è, inoltre non aiuta a comprendere dinamiche e workflow più attuali.
Amazon Verified review Amazon
Cliente de Amazon Dec 05, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Muy completo en conceptos y en cómo administrar tus assets en tu proyecto. Solo debería tener más ejercicios prácticos
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.