Skip to Main Content
Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation
book

Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation

by Matthew Johnson, James A. Henley
December 2014
Beginner content levelBeginner
384 pages
11h 15m
English
Addison-Wesley Professional
Content preview from Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation

Organizing the Code

While all of our code is functional, there are potentially numerous ways in which we could better organize it. We’ll look at a pair of ways that will help us both reduce the visual clutter of working with a large script and reduce the odds of introducing bugs by centralizing some of our important data.

Using Regions in Code

Use of the #region and #endregion keywords would allow us to break our code up into collapsible sections. Let’s take a look at one of our largest scripts—PlayerController—and see how we could break it down using regions. Open the script and adjust it as shown in Listing 12.1.

Listing 12.1 Regions in the PlayerController Script

public class PlayerController : MonoBehaviour ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Development with MonoGame: Build a 2D Game Using Your Own Reusable and Performant Game Engine

Game Development with MonoGame: Build a 2D Game Using Your Own Reusable and Performant Game Engine

Louis Salin, Rami Morrar
Game Development Projects with Unreal Engine

Game Development Projects with Unreal Engine

Hammad Fozi, Gonçalo Marques, David Pereira, Devin Sherry

Publisher Resources

ISBN: 9780133523416Purchase book