Reader small image

You're reading from  Getting Started with Unity 5

Product typeBook
Published inMay 2015
Publisher
ISBN-139781784398316
Edition1st Edition
Tools
Right arrow
Author (1)
Dr. Edward Lavieri
Dr. Edward Lavieri
author image
Dr. Edward Lavieri

Dr. Edward Lavieri is a veteran software engineer and developer with a strong academic background. He earned a Doctorate of Computer Science from Colorado Technical University, an MS in Management Information Systems (Bowie State University), an MS in Education (Capella University), and an MS in Operations Management (University of Arkansas). He has been creating and teaching computer science courses since 2002. Edward retired from the U.S. Navy as a Command Master Chief after 25 years of active service. He is the founder and creative director of three19, a software design and development studio. Edward has authored more than a dozen technology books, including several on Java.
Read more about Dr. Edward Lavieri

Right arrow

Chapter 7. Polishing and Optimizing the Game

Okay, all of the heavy lifting is completed. We've completed our game and can play it without running into any errors. You can download the final Unity project from the book's web page. You can extend the game, experiment, and make it your own.

Now it is time to clean things up a bit. Our game needs some final touches to help make it shine. In this chapter, I'll show you how to add audio and visual effects such as sound effects, shadows, and lighting effects. We'll use some of Unity's functionality and explore how we can expand them.

This chapter begins with a brief discussion of the importance of audio and visual effects in games. From that discussion, the chapter shifts focus and shows you how to implement specific effects. We'll start with some key sound effects and then add shadows and lighting effects to our game.

After reading this chapter, you will:

  • Be able to add sound effects

  • Be able to add shadows to game assets

  • Be able to create lighting...

Sight and sound


Let's try a quick experiment. Sit down at your computer, console, or mobile device and get set to play your favorite game. First, mute the sound. Now, adjust the video settings so the screen is dim and, if possible, black and white. Okay, now play your game. I'll bet the game is not as fun as you remember. Go ahead and reset any settings you changed. Now, play the game again. What a difference!

Even if you did not go along with my experiment, I'll bet you understand the impact those changes would have on your ability to enjoy the gaming experience. This underlines just how important audio and visual effects are for gamers. Imagine an explosion without a sound. You get the point, audio and visual effects are important. So, why talk about them at all? Adding appropriate audio to games is considered a best practice. We'll consider best practices in implementing audio and video in Unity.

Unity's sound capabilities

Unity has great support for playing audio in games. There are a few...

Rendering options


As you know, rendering is the act of creating a 3D image from images, colors, and shading. In other words, creating a visual presentation. Depending on your game, this can be a lot of work for the Unity engine. We can keep our eye on this by selecting Window | Profiler from the top menu. This brings up the Profiler window.

The Profiler window

The Profiler window gives us a view of CPU usage, rendering, memory, audio, physics, and physics (2D). Reviewing these areas can help us determine how our game is performing and where there are potential areas to optimize. We'll focus on the Rendering section:

You can switch between any of these Profiler areas. To look at Rendering, select that from the left pane of the Profiler window. When you put the game in play mode and start navigating the world, the Rendering area of the Profiler window will start to populate, as shown in the following screenshot:

In addition to the color-coded charting that happens on the top portion of the Profiler...

Optimizing scripts


We want our scripts to be optimal in regards to memory usage and processing. A great approach to script optimization is to simply code your game and run it with the Profiler window open and select the CPU Usage tab from the left pane, as shown in the following screenshot:

Using this view, you can see what processes are taking the most CPU power. The visual graph makes it easy to spot significant jumps in CPU usage. The Overview section, which can be found below the visual graph, provides a very detailed view of how much CPU processing is allocated to each object and process.

Another section of the Profiler window is the Memory tab. Reviewing that tab's information can tell you how much memory is allocated, how much system memory is used, and counts of Textures, Meshes, Materials, AnimationClips, AudioClips, Assets, and GameObjects:

Once we know where our problems or potential issues are, we can do a few things to optimize our scripts:

  • We can destroy objects that we no longer...

Summary


In this chapter, we have looked at the importance of audio and visual effects as a method of enhancing the gaming experience for our users. We explored Unity's capabilities to help us manage audio with audio listeners, audio clips, and audio sources. We put our new knowledge into practice and add two sound effects to our game: pigs crying and a "points" sound that is played when our game character picks up an item. We looked at visual effects included implementing a spotlight orb with halo, casting shadows, and trail rendering.

We also looked at how to optimize our game with Rendering settings. You were introduced to Unity's Profiler window and how to read the Rendering, CPU usage, and memory data. You learned about rendering optimization and the specific techniques of imposing limits and baking images.

Lastly, we looked at script optimization to ensure our game performs well.

In the next, final chapter, we'll look at what you can do to improve our Little Farmer Colt game, the Unity...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Getting Started with Unity 5
Published in: May 2015Publisher: ISBN-13: 9781784398316
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Dr. Edward Lavieri

Dr. Edward Lavieri is a veteran software engineer and developer with a strong academic background. He earned a Doctorate of Computer Science from Colorado Technical University, an MS in Management Information Systems (Bowie State University), an MS in Education (Capella University), and an MS in Operations Management (University of Arkansas). He has been creating and teaching computer science courses since 2002. Edward retired from the U.S. Navy as a Command Master Chief after 25 years of active service. He is the founder and creative director of three19, a software design and development studio. Edward has authored more than a dozen technology books, including several on Java.
Read more about Dr. Edward Lavieri