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 2D game development
Mastering Unity 2D game development

Mastering Unity 2D game development: Mastering Unity 2D Game Development will give your game development skills a boost and help you begin creating and building an RPG with Unity 2D game framework

eBook
€24.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering Unity 2D game development

Chapter 2. Building a Character

It's time to start putting in the building blocks that will make up your game, starting with the setting up the project and then on to main character. It's an important first step as most of your game's core logic and framework generally centers on the main protagonist and highlights exactly how the player will interact with the game.

Here, we are aiming to create a 2.5D style in-game world where the player can explore each town and have random encounter scenes to fight off those pesky bad guys. So, first we need to get our character in and moving.

The following is the list of topics that will be covered in this chapter:

  • Designing a good class structure
  • Planning and designing behaviors
  • Importing sprites
  • Setting up user control effectively

Note

For this game, we will use the excellent, free Unity games starter kit resources, which can be found at http://wootstudio.ca/win8platstarter (towards the bottom of the page).

There are several different...

Getting your project started – the right way

Before you start your project for real, you should consider how you intend to set it up and architect your project in the long term. I've looked at or worked with far too many projects that have created problems for themselves by just diving in rather than designing the outline for the project at the start.

Your game and your assets are not the only things to consider when starting a fresh project. Sure, you can start importing assets, creating scripts, and getting things running; most Proof of Concept (POC) projects start this way. Once your project is of a sufficient size and you start expanding on your initial concept, you'll realize that you have issues with regards to picking up items and putting them together. Then, you will start devising new ways to organize your project and eventually find that it's an unmanageable mess; nevertheless, you will stride on, taking longer and longer to produce new content or add new...

Understanding components

Components in Unity are the building blocks of any game; almost everything you will use or apply will end up as a component on a GameObject inspector in a scene.

Until you build your project, Unity doesn't know which components will be in the final game when your code actually runs (there is some magic applied in the editor). So, these components are not actually attached to your GameObject inspector but rather linked to them.

Accessing components using a shortcut

Now, in the previous Unity example, we added some behind-the-scenes trickery to enable you to reference a component without first discovering it. We did this by adding shortcuts to the MonoBehavior class that the game object inherits from. You can access the components with the help of the following code:

this.renderer.collider.attachedRigidbody.angularDrag = 0.2f;

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www...

Creating the project

First things first! To ensure that you have all the bases covered, you need to start a new project. For 2D, however, you need to ensure that you start the project using the 2D game template in the Unity New Project wizard, as shown in the following screenshot:

Creating the project

If you accidentally leave the 3D option set (which is the default) as is, don't worry! You can change this at any time for your project through Editor Settings. To open Editor Settings, simply navigate to Edit | Project Settings | Editor, as shown in the following screenshot:

Creating the project

Lastly, let's create the folder structure for the project, as shown in the following screenshot, using the guidance provided earlier:

Creating the project

At this point, it's important to note that we will most likely not use all of these folders during the course of the book. Nevertheless, it is a good working practice to get these set up for every project just so that you have a standard template.

Note

This book will cover the process of creating...

Classes

Architecting the core of your game from the beginning is an often-skipped process. Because we're too eager to just get on and build our game, let's jump straight in and start placing assets in a scene, adding them as we go. This kind of practice is fine for prototypes (mostly, however, even with prototypes, a level of architecture is usually required). When building your actual product, however, without setting up a proper architecture from the beginning, you are heading toward a world of utter mess.

When we say architecture, it doesn't mean that you need to design everything (but it helps). You just need to ensure that you plan what you are going to build before you build it instead of thinking about stuff and checking Google for information on how to do it. Even if you are using some kind of an agile method, you should have a good framework and goal for each sprint as you plan for each sprint. This will guide you on what should be done and when, not just designing...

Planning behaviors

Behaviors are just a fancy way of saying things or interactions that will happen in the game. Breaking down these actions or reactions in this way helps to componentize how we think our game will work. Stopping and thinking about this from the very beginning means we won't get too many surprises later on. (There are always surprises after a good night's sleep.)

For example, behaviors can take the following forms:

  • Attacking another entity
  • Taking damage
  • Collecting the loot, which could be money or items
  • Teleporting to another land

It is also important to note that visual effects as the result of a behavior or action are different to those that affect the characteristics of the game's object. You may have a visual representation as the result of a behavior or action (for example, a particle effect when taking damage or the character swinging their sword to attack), but in Unity especially, you have to keep these separate. We will cover more on this later.

Note

In...

Getting your project started – the right way


Before you start your project for real, you should consider how you intend to set it up and architect your project in the long term. I've looked at or worked with far too many projects that have created problems for themselves by just diving in rather than designing the outline for the project at the start.

Your game and your assets are not the only things to consider when starting a fresh project. Sure, you can start importing assets, creating scripts, and getting things running; most Proof of Concept (POC) projects start this way. Once your project is of a sufficient size and you start expanding on your initial concept, you'll realize that you have issues with regards to picking up items and putting them together. Then, you will start devising new ways to organize your project and eventually find that it's an unmanageable mess; nevertheless, you will stride on, taking longer and longer to produce new content or add new features.

The best advice...

Understanding components


Components in Unity are the building blocks of any game; almost everything you will use or apply will end up as a component on a GameObject inspector in a scene.

Until you build your project, Unity doesn't know which components will be in the final game when your code actually runs (there is some magic applied in the editor). So, these components are not actually attached to your GameObject inspector but rather linked to them.

Accessing components using a shortcut

In most Unity examples, you are shown how to access components through scripts by using shortcuts to the MonoBehaviour class that the game object inherits from. Accessing the components with the help of the following code:

this.renderer.collider.attachedRigidbody.angularDrag = 0.2f;

Tip

If you need any help with this title or have any suggestions on it, join in on the support forum for the book at http://bit.ly/MasteringUnity2DForums. The forum will also keep you updated on any announcements on the title, so...

Creating the project


First things first! To ensure that you have all the bases covered, you need to start a new project. For 2D, however, you need to ensure that you start the project using the 2D game template in the Unity New Project wizard, as shown in the following screenshot:

If you accidentally leave the 3D option set (which is the default) as is, don't worry! You can change this at any time for your project through Editor Settings. To open Editor Settings, simply navigate to Edit | Project Settings | Editor, as shown in the following screenshot:

Lastly, let's create the folder structure for the project, as shown in the following screenshot, using the guidance provided earlier:

At this point, it's important to note that we will most likely not use all of these folders during the course of the book. Nevertheless, it is a good working practice to get these set up for every project just so that you have a standard template.

Note

This book will cover the process of creating your own project...

Classes


Architecting the core of your game from the beginning is an often-skipped process. Because we're too eager to just get on and build our game, let's jump straight in and start placing assets in a scene, adding them as we go. This kind of practice is fine for prototypes (mostly, however, even with prototypes, a level of architecture is usually required). When building your actual product, however, without setting up a proper architecture from the beginning, you are heading toward a world of utter mess.

When we say architecture, it doesn't mean that you need to design everything (but it helps). You just need to ensure that you plan what you are going to build before you build it instead of thinking about stuff and checking Google for information on how to do it. Even if you are using some kind of an agile method, you should have a good framework and goal for each sprint as you plan for each sprint. This will guide you on what should be done and when, not just designing the project on...

Left arrow icon Right arrow icon

Description

If you have C# knowledge but now want to become truly confident in creating fully functional 2D RPG games with Unity, then this book will show you everything you need to know.

What you will learn

  • Explore the new features introduced in Unity3D 4.3 by building your own RPG game Delve into the new sprite importing and rendering system Master the best parts of the new Sprite animation system and improved Mecanim features Make the most of your rendering with tags, layers, sprite sorting, and ordering Dissect the proper use of Delegates, Events, and Messaging, including tips and tricks, and build a full RPG conversation system Do battle with Mecanim-based AI and state machines Build for success with tips on marketing, monetization, and deployment Drive home the platform of choice and expand into deployment/editor extensions

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 26, 2014
Length: 474 pages
Edition : 1st
Language : English
ISBN-13 : 9781849697354
Vendor :
Unity Technologies
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Aug 26, 2014
Length: 474 pages
Edition : 1st
Language : English
ISBN-13 : 9781849697354
Vendor :
Unity Technologies
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 82.98
Unity Game Development Blueprints
€36.99
Mastering Unity 2D game development
€45.99
Total 82.98 Stars icon

Table of Contents

14 Chapters
1. Overview Chevron down icon Chevron up icon
2. Building a Character Chevron down icon Chevron up icon
3. Getting Animated Chevron down icon Chevron up icon
4. The Game World Chevron down icon Chevron up icon
5. NPCs and Interactions Chevron down icon Chevron up icon
6. The Big Wild World Chevron down icon Chevron up icon
7. Encountering Enemies and Running Away Chevron down icon Chevron up icon
8. Shopping for Weapons Chevron down icon Chevron up icon
9. Getting Ready to Fight Chevron down icon Chevron up icon
10. Fight and Gain XP Chevron down icon Chevron up icon
11. Onward Wary Traveler Chevron down icon Chevron up icon
12. Deployment and Beyond Chevron down icon Chevron up icon
A. Additional Resources Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(21 Ratings)
5 star 38.1%
4 star 23.8%
3 star 14.3%
2 star 23.8%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Suraj May 18, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I just got it , thank you
Subscriber review Packt
Brett A. Brown Sep 14, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent beginner book. Very clear instructions with lots of screenshots. By noon I could make my monkey dance!
Amazon Verified review Amazon
Heleen Durston Nov 11, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Another Unity game engine book from Packtpub was released in October, “Mastering Unity 2D Game Development” by Simon Jackson. This is an intermediate to advanced guide to using the 2D features of Unity. The book centers around creating a 2D RPG complete with world map, a conversation system, a store, and the beginnings of a battle system. When the book was initially released there were a variety of typos and show-stopping problems with the book and code. Packtpub has recently reissued the book and code and now everything works well. Chapter 1 is an overview of the updates that occurred in Unity 4.3. I went through the book using Unity 4.6 beta and had no issues. “Mastering Unity 2D Game Development” is definitely meant for those with some experience using Unity and in particular the C# programming language. Many links are provided for reference throughout the book; but knowing how to use coroutines and delegates will definitely help you complete the examples in the book. Chapters 2 and 3 explain how to set up the foundation of the RPG project and begin with having you create a 2D game character and animate it. Importing sprites and using the Sprite editor are discussed and then Unity’s Mecanim animation system is explained while the main character gets animated. In chapter 4 the background for your initial scene is created and then populated with some trees, rocks and even store and house sprites. This chapter also talks about transitioning from the background edges to another scene that you will set-up. Chapter 5 is a heavily scripting-oriented chapter and has you create some NPCs and then set-up a conversation system. This chapter also discusses co-routines and how to use them in Unity. Chapter 6 discusses places online to have maps drawn for you and alternately gives advice on how to create your own game world map. The world map for the game is placed in your project and a nice fade-in technique is used to transition between the world map and the local scene for your player. In chapter 7 a battle system is created and the book explains how to have goblins randomly spawn in your scene. In chapter 8 a shop is created so that you can purchase a sword to fight the goblins from chapter 7. Both chapters discuss the creation of an inventory system and how to add the sword stats as a bonus to the battle system. Chapter 9 talks about using a state system for the battle and also programming a user interface system to keep the player informed about the battle. Everything seemed to work fine using the ‘old’ user interface system in Unity 4.6 beta. For those that don’t know the UI was quite significantly updated in Unity 4.6; but all the code in the books seems to work fine. Chapter 10 is all about creating particle systems for the battles in your RPG and chapter 11 discusses expanding the Unity editor to create some nice menus for your game. I found chapter 11 a really interesting read as I was not aware that you could expand Unity that much for your own purposes. Chapter 12 concludes the book with information on building your game for different platforms. There is also a lot of links listed presenting information on a variety of tutorials and tools for working with Unity. This is a great book for Unity and one that I will keep around for reference on how to do a lot of programming in Unity. I am really pleased that I had a chance to read the book and try the code. The link to the book on Packtpub is https://www.packtpub.com/game-development/mastering-unity-2d-game-development. You can also find the download with all the assets for the RPG project there and a PDF that has all the pictures from the book. Simon Jackson has a website at http://darkgenesis.zenithmoon.com/ and a forum for the book at http://darkgenesis.zenithmoon.com/DarkGenesisForums/forum/book-forums/ .
Amazon Verified review Amazon
Shaun Walsh Nov 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
So far so good. Havent made it too far into the book yet, but of all the Unity books I have read so far, this one is by far the best. Everything is broke down nice and simple, and there are plenty of illustrations to go along with it. Author is well versed and thorough. My only complaint (not about the book) but is with the kindle version. Please fix your format so that highlighted text works please.
Amazon Verified review Amazon
Muhammad Bilal Sep 01, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
great for people interested in game development
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.