Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Getting Started with Unity 5.x 2D Game Development
Getting Started with Unity 5.x 2D Game Development

Getting Started with Unity 5.x 2D Game Development: Enter the world of 2D Game development with Unity 5.x

eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Getting Started with Unity 5.x 2D Game Development

Chapter 2. Baking Cupcake Towers

In this second chapter, we will begin to build our game. We will see how it's possible to place objects in 2D space and create templates for the most used objects. Furthermore, we will see how Unity deals with scripts, and we will write a couple of our own for our game.

In particular, we will cover the following topics:

  • Placing objects in 2D space
  • Setting up the map for our game
  • Using tags and layers
  • Creating Prefabs (templates for game objects)
  • Creating new scripts
  • Basic concepts of scripting in Unity
  • Writing our first two scripts for our game

Like all the other chapters of this book, you will find the Homework section at the end. It has a range of different exercises for you to do to improve your skills and implement a range of different functionalities into your game.

So, let's get started by learning how to place 2D objects into the scene.

2D objects

In the previous chapter, we saw that 2D objects in Unity are Sprites. However, we didn't mention how to import them into the scene.

The easiest way to bring your Sprites into the scene is to drag and drop them from the Project panel into the Scene view. Unity will automatically create a new game object with the same name of the Sprite along with a Sprite Renderer attached. We have already covered this component in the previous chapter. Since we will not use Sorting Layers (as we decided in the previous chapter), we don't need to change any settings when dragging a new Sprite into the scene.

Another way to add Sprites to the scene is by right-clicking on the Hierarchy panel and then 2D Object | Sprite. However, in the Sprite Renderer, you need to specify which Sprite to use.

Let's bring the Pink_Sprinkle Sprite into our scene (you can find it in the Graphics/projectiles folder within the projectiles_sheet_01 file). It appears like this in the Scene view:

2D objects

Since Sprites...

Parenting game objects

Each game object can have a parent. This means that the game objects will move, rotate, and scale along with its parent.

I could use many words to explain this concept, but there are things which videos can explain better than words. As such, there is a very short video explaining, The Hierarchy and Parent-Child relationships at: https://unity3d.com/learn/tutorials/topics/interface-essentials/hierarchy-and-parent-child-relationships.

I recommend that you to watch it before you continue reading this book. I'll wait for you here.

Difference between world coordinates and local coordinates

Every game object in Unity has a position, but a position needs a reference frame (more about reference frames later in Chapter 5The Secret Ingredient Is a Dash of Physics). In particular, Unity offers two ways to see (and set) coordinates:

  • World coordinates: These are absolute coordinates of where the game object is located (by absolute, I mean with respect to the world frame, which is considered to be absolute in the game)
  • Local coordinates: These are the coordinates of where the game object is with respect to its parent

You can easily switch between the two coordinates with a toggle in the upper-right part of the Unity interface, as shown in the following screenshot:

Difference between world coordinates and local coordinates

As shown in the preceding screenshot, they are both toggles, but the one to switch between world and local coordinates is the one on the left. At the moment, it is selected to be on Global, which means on world coordinates.

Ordering the different layers with Z-Buffering

In the previous chapter, we decided to use Z-Buffering instead of Sorting Layers. However, we need to decide which elements of our game will be in the foreground compared to the others.

In addition, it is important to keep in mind how the camera is set. Select Main Camera, which should be the only camera in the scene. This is what the Inspector should look like:

Ordering the different layers with Z-Buffering

As you can see, by default, its Z value on the the position is set to -10. This means you cannot have any greater negative values (that means smaller than -10) in the Z value of a Sprite, otherwise it will not be rendered. For our purpose, -10 is perfect, and we will stick with it.

Next, we need to assign a Z value to all the elements that we have. We can start to place the map in the background, by assigning the lowest depth (maximum Z value) that we have in mind; in this case it's zero.

Then, we would like to have the enemies. Therefore, we can set their Z value to -1. After...

2D objects


In the previous chapter, we saw that 2D objects in Unity are Sprites. However, we didn't mention how to import them into the scene.

The easiest way to bring your Sprites into the scene is to drag and drop them from the Project panel into the Scene view. Unity will automatically create a new game object with the same name of the Sprite along with a Sprite Renderer attached. We have already covered this component in the previous chapter. Since we will not use Sorting Layers (as we decided in the previous chapter), we don't need to change any settings when dragging a new Sprite into the scene.

Another way to add Sprites to the scene is by right-clicking on the Hierarchy panel and then 2D Object | Sprite. However, in the Sprite Renderer, you need to specify which Sprite to use.

Let's bring the Pink_Sprinkle Sprite into our scene (you can find it in the Graphics/projectiles folder within the projectiles_sheet_01 file). It appears like this in the Scene view:

Since Sprites are also GameObjects...

Parenting game objects


Each game object can have a parent. This means that the game objects will move, rotate, and scale along with its parent.

I could use many words to explain this concept, but there are things which videos can explain better than words. As such, there is a very short video explaining, The Hierarchy and Parent-Child relationships at: https://unity3d.com/learn/tutorials/topics/interface-essentials/hierarchy-and-parent-child-relationships.

I recommend that you to watch it before you continue reading this book. I'll wait for you here.

Difference between world coordinates and local coordinates


Every game object in Unity has a position, but a position needs a reference frame (more about reference frames later in Chapter 5The Secret Ingredient Is a Dash of Physics). In particular, Unity offers two ways to see (and set) coordinates:

  • World coordinates: These are absolute coordinates of where the game object is located (by absolute, I mean with respect to the world frame, which is considered to be absolute in the game)

  • Local coordinates: These are the coordinates of where the game object is with respect to its parent

You can easily switch between the two coordinates with a toggle in the upper-right part of the Unity interface, as shown in the following screenshot:

As shown in the preceding screenshot, they are both toggles, but the one to switch between world and local coordinates is the one on the left. At the moment, it is selected to be on Global, which means on world coordinates.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build a complete and exciting 2D Tower Defense game from scratch.
  • Understand and learn to perform each phase of the game development pipeline
  • Homework and exercises to improve your skills and take them to the next level

Description

Want to get started in the world of 2D game development with Unity? This book will take your hand and guide you through this amazing journey to let you know exactly what you need to build the games you want to build, without sacrificing quality. You will build a solid understanding of Unity 5.x, by focusing with the embedded tools to develop 2D games. In learning about these, along with accurate explanations and practical examples, you will design, develop, learn how to market and publish a delectable Tower Defense game about cupcakes versus pandas. Each chapter in this book is structured to give you a full understanding on a specific aspect of the workflow pipeline. Each of these aspects are essential for developing games in Unity. In a step-by-step approach, you will learn about each of the following phases: Game Design, Asset Importing, Scripting, User Interfaces, Animations, Physics, Artificial Intelligence, Gameplay Programming, Polishing and Improving, Marketing, Publishing and much more. This book provides you with exercises and homework at the end of each chapter so that you can level up your skills as a Unity game developer. In addition, each of these parts are centered on a common point of discussion with other learners just like you. Therefore, by sharing your ideas with other people you will not only develop your skills but you will also build a network.

Who is this book for?

If you are looking forward to get started with 2D game development, either if you are a newcomer to this world, or you came from 3D games or other game engines, this book is for you. Although there are many references to other resources throughout the book, it is assumed that you have a general understanding of C# and its syntax and structure.

What you will learn

  • Import and set up assets for 2D game development
  • Design and implement dynamic and responsive User Interfaces
  • Create and handle complex animation systems
  • Unlock all the potentiality of the physics engine
  • Implement Artificial Intelligence algorithms to give intelligence to your NPCs
  • Script gameplay and overall bring your ideas to life
Estimated delivery fee Deliver to Latvia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 10, 2017
Length: 478 pages
Edition : 1st
Language : English
ISBN-13 : 9781784397173
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Latvia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Publication date : Feb 10, 2017
Length: 478 pages
Edition : 1st
Language : English
ISBN-13 : 9781784397173
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 111.97
Unity 5.x 2D Game Development Blueprints
€32.99
Getting Started with Unity 5.x 2D Game Development
€36.99
Mastering Unity 5.x
€41.99
Total 111.97 Stars icon
Banner background image

Table of Contents

8 Chapters
1. A Flat World in Unity Chevron down icon Chevron up icon
2. Baking Cupcake Towers Chevron down icon Chevron up icon
3. Communicating with the Player – the User Interface Chevron down icon Chevron up icon
4. No Longer Alone – Sweet-Toothed Pandas Strike Chevron down icon Chevron up icon
5. The Secret Ingredient Is a Dash of Physics Chevron down icon Chevron up icon
6. Through a Sea of Sprinkles – Navigation in Artificial Intelligence Chevron down icon Chevron up icon
7. Trading Cupcakes and the Ultimate Battle for the Cake – Gameplay Programming Chevron down icon Chevron up icon
8. What Is beyond the Cake? Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 0%
2 star 33.3%
1 star 0%
Bart Knowles Feb 27, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
In the vast sea of technical manuals, each of us is looking for something specific. I found exactly what I wanted in this book: a clear, step-by-step guide to writing a real game with Unity. I was not looking for abstract theory or academic blah blah, therefore if you are looking for those, you shouldn't probably buy this one.But if you are, as I am, into serious game programming and want to learn without useless fatigue how to develop your own game, together with priceless insider tips along the way, then you've come to the right place. I haven't read it all yet (a bit more than halfway through), but I am programming as I proceed, and the tower defense game that is coming out is pretty cool. It won't be my final product, of course, but I am planning on experimenting with variations until I get to my perfect tower defense game!
Amazon Verified review Amazon
Stelvio Feb 25, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm getting started! And this book's helping me so much. A few days ago I even proposed it to my teacher, I'm quite sure he's going to adopt it for his course.
Amazon Verified review Amazon
TechReader Feb 21, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I've read enough technical books over the years to know that reading a really great one is effortless, and reading a not so great one can be the most frustrating thing. This one's not so great. The main problem this book suffers from is that the author tells you what he wants you to do, but not EXACTLY what he wants you to do. Quick example, in an early chapter the author explains all about the Sprite Editor by stepping through an example with an actual sprite. Then he tells you to do the rest of the sprites in the example game the same way before moving on. When you try do it the same way, you wind up with sprites getting cut right through the middle of the graphics and you're left wondering if this is intentional or not? Then it takes way too much time and effort to decide on what to do next, and once you do decide, you don't know if you've done it right or not. This happens over and over again throughout the book, and it takes quite an effort to figure out what's going on. If you like a challenge and a struggle while learning, then this book might be for you. If you learn better from clear instructions and want to breeze through each topic like I do, then look for another Unity book.
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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela