Book Image

Mastering Unity 2D Game Development - Second Edition

By : Ashley Godbold, Simon Jackson
Book Image

Mastering Unity 2D Game Development - Second Edition

By: Ashley Godbold, Simon Jackson

Overview of this book

The Unity engine has revolutionized the gaming industry, by making it easier than ever for indie game developers to create quality games on a budget. Hobbyists and students can use this powerful engine to build 2D and 3D games, to play, distribute, and even sell for free! This book will help you master the 2D features available in Unity 5, by walking you through the development of a 2D RPG framework. With fully explained and detailed C# scripts, this book will show you how to create and program animations, a NPC conversation system, an inventory system, random RPG map battles, and full game menus. After your core game is complete, you'll learn how to add finishing touches like sound and music, monetization strategies, and splash screens. You’ll then be guided through the process of publishing and sharing your game on multiple platforms. After completing this book, you will have the necessary knowledge to develop, build, and deploy 2D games of any genre!
Table of Contents (20 chapters)
Mastering Unity 2D Game Development - Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface

Preface

The Unity engine has revolutionized the gaming industry, by making it easier than ever for indie game developers to create quality games on a budget. Hobbyists and students can use this powerful engine to build 2D and 3D games, to play, distribute, and even sell for free! Unity 4.3 dramatically reformed the way developers could create 2D games when they included sprite rendering, 2D physics, and sprite key-frame animation. Unity 4.6 further shook the gaming world by adding a new and elegant UI system that perfectly complimented the 2D games developers began creating. Now, Unity 5 has arrived! And this text will explore all the wonderful features it has to offer for 2D game development.

In this book, you will learn how to build an RPG game framework, learning lots of tips and tricks along the way. You will start by making a character and a village for the character to interact with NPCs. Then you will develop an overworld map for the character to explore that will be loaded with enemies who randomly attack her. After that, you'll cover the process involved in setting up a turn based battle system along with all of the necessary steps for creating a functional GUI. Following that, you'll develop a shop and inventory system and then implement sound and music. By the end of this book, you will be able to architect, create, deploy, your game as well as have the knowledge to build and customize the Unity editor.

What this book covers

Chapter 1, Overview. This chapter gives a basic overview of the 2D features provided within Unity 5. It also provides general guidance for finding free assets to use within 2D projects. Lastly, it points out key differences between Unity 5 and Unity 4.

Chapter 2, Building your Project and Character. This chapter covers the steps necessary to start building a project. It describes object oriented programming, how it is used in Unity, and the basic structure of a class in C# using MonoDevelop. This chapter also describes the process of importing, editing, and implementing, 2D sprites into the Unity engine, as well as the programming required to move the sprite around the screen with the player's interaction.

Chapter 3, Getting Animated. This chapter introduces animation in Unity by utilizing the various animation components. It describes the process of converting a sprite sheet to an animation clip and implementing the Animator component. It also describes the process of setting up the Animator Controller and explains how to implement animation parameters using scripting.

Chapter 4, The Town View. This chapter explains the process of setting up the town in which the character will walk around. It also explains the process of working with the camera and how to program the functionality necessary for the character to interact with her environment.

Chapter 5, Working with Unity's UI System. This chapter gives a general overview of the UI system implemented in Unity 4.6.

Chapter 6, NPCS and Interactions. This chapter covers the overall structure of interacting with non-player characters within an RPG. It then describes the process of writing and implementing the code necessary to allow the player to speak with the NPCs, and displaying the conversation utilizing the UI system.

Chapter 7, The World Map. This chapter discusses the process of building a map for the player to navigate and allowing the player character to exit the initial town.

Chapter 8, Encountering Enemies and Running Away. This chapter discusses the process of creating a battle scene that contains randomly spawning enemies. It then covers the programming required to have the player character transition in to random battles and transition back to the map by selecting the option to run away.

Chapter 9, Getting Ready to Fight. This chapter discusses the process of developing a battle introduction animation and the GUI that will allow the player to interact with the battle.

Chapter 10, The Battle Begins. This chapter further develops the battle system, by implementing the code that allows the player to select various attacks, incorporating particle systems to represent attacks, and utilizing an event system.

Chapter 11, Shopping for Items. This chapter discusses the process of creating a shop in which the player can buy items and an inventory system in which the player can save the purchased items.

Chapter 12, Sound and Music. This chapter covers the basics of sound integration utilizing audio listeners and sources, by adding background music and a sound effect when the player purchases an item.

Chapter 13, Putting a Bow on It. This chapter covers the finishing touches necessary to create a complete game. This includes packaging the game, implementing a splash screen and menu system, extending the editor, and adding a system to save the player’s data.

Chapter 14, Deployment and Beyond. This final chapter discusses how to convert the final game to a playable game.

What you need for this book

In order to follow this book, you will need the Unity game engine available at https://unity3d.com/get-unity/download.

You will need to download version 5.3 or higher. This text was written using 5.3.4. If for some reason, you want to get Unity 5.3.4 instead of the most recent version, you can get archived versions from https://unity3d.com/get-unity/download/archive.

To get the art assets and code discussed within the book, you should download the book's support files.

Who this book is for

This book is intended for anyone looking to get started in developing 2D games with Unity 5 or anyone already familiar with Unity 2D wishing to expand or supplement their current Unity knowledge. A basic understanding of programming logic is needed to begin learning with this book, but intermediate and advanced programming topic are explained thoroughly so that coders of any level can follow along. Previous programming experience in C# is not required.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "This is done by calling DontDestroyOnLoad when you initialize the class."

A block of code is set as follows:

//Set the public property of the singleton 
MySingletonManager.Instance.MyTestProperty = "World Hello"; 
 
//Run the public method from the singleton 
MySingletonManager.Instance.DoSomethingAwesome();

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "After selecting Create project, you'll be brought to the Editor Window"

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code 

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-Unity-2D-Game-Development-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book 

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MasteringUnity2DGameDevelopmentSecondEdition_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.