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
Unity 5.x Cookbook
Unity 5.x Cookbook

Unity 5.x Cookbook: More than 100 solutions to build amazing 2D and 3D games with Unity

eBook
₱1742.99 ₱2490.99
Paperback
₱3112.99
Subscription
Free Trial

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

Unity 5.x Cookbook

Chapter 2. Inventory GUIs

In this chapter, we will cover the following topics:

  • Creating a simple 2D mini-game – SpaceGirl
  • Displaying single object pickups with carrying and not-carrying text
  • Displaying single object pickups with carrying and not-carrying icons
  • Displaying multiple pickups of the same object with text totals
  • Displaying multiple pickups of the same object with multiple status icons
  • Revealing icons for multiple object pickups by changing the size of a tiled image
  • Displaying multiple pickups of different objects as a list of text via a dynamic List<> of PickUp objects
  • Displaying multiple pickups of different objects as text totals via a dynamic Dictionary<> of PickUp objects and "enum" pickup types
  • Generalizing multiple icon displays using UI Grid Layout Groups (with scrollbars!)

Introduction

Many games involve the player collecting items or choosing from a selection of items. Examples could be collecting keys to open doors, collecting ammo for weapons, choosing from a collection of spells to cast, and so on.

The recipes in this chapter offer a range of solutions for displaying to the player whether they are carrying an item or not, if they are allowed more than one of an item, and how many they have.

The big picture

The two parts of software design for implementing inventories relate to, first, how we choose to represent the data about inventory items (that is, the data types and structures to store the data) and, secondly, how we choose to display information about inventory items to the player (the UI: User Interface).

Also, whilst not strictly inventory items, player properties such as lives left, health, or time remaining can also be designed around the same concepts that we present in this chapter.

We need to first think about the nature of different inventory...

Creating a simple 2D mini-game – SpaceGirl

This recipe presents the steps to create the 2DSpaceGirl mini-game, on which all the recipes of this chapter are based.

Getting ready

For this recipe, we have prepared the images you need in a folder named Sprites in the 1362_02_01 folder. We have also provided the completed game as a Unity package in this folder named Simple2DGame_SpaceGirl.

How to do it...

To create the simple 2D mini-game Space Girl follow these steps:

  1. Create a new, empty 2D project.
  2. Import supplied folder Sprites into your project.
  3. Convert each sprite image to be of type Sprite (2D and UI). To do this, select the sprite in the Project panel, then, in the Inspector, change choose Sprite (2D and UI) from the drop-down menu Texture Type, and click on the Apply button, as shown in the following screenshot:
    How to do it...
  4. Set the Unity Player screen size to 800 x 600: choose the Edit | Project Settings | Player menu, then for option Resolution and Presentation uncheck Default is Full Screen, and...

Displaying single object pickups with carrying and not-carrying text

Often the simplest inventory situation is to display text to tell players if they are carrying a single item (or not).

Getting ready

This recipe assumes that you are starting with the project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter. So, either make a copy of that project or do the following:

  1. Create a new, empty 2D project.
  2. Import the Simple2Dgame_SpaceGirl package.
  3. Open scene Scene1 (in the Scenes folder).
  4. Set the Unity Player screen size to 800 x 600 (see the previous recipe for how to do this) and select this resolution in the Game panel the drop-down menu.
  5. Convert each sprite image to be of type Sprite (2D and UI). In the Inspector, choose Sprite (2D and UI) from drop-down menu Texture Type, and click on the Apply button.

For this recipe, we have prepared the font you need in a folder named Fonts in the 1362_02_02 folder.

How to do it...

To display text to inform the user about the status of carrying...

Displaying single object pickups with carrying and not-carrying icons

Graphic icons are an effective way to inform the player that they are carrying an item. In this recipe, if no star is being carried, a grey-filled icon in a blocked-off circle is displayed; then, after the star has been picked up, a yellow-filled icon is displayed, as shown in the following screenshot.

Displaying single object pickups with carrying and not-carrying icons

In many cases, icons are clearer (they don't require reading and thinking about) and can also be smaller onscreen than text messages for indicating player status and inventory items.

Getting ready

This recipe assumes that you are starting with the project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter.

How to do it...

To toggle carrying and not-carrying icons for a single object pickup, follow these steps:

  1. Start with a new copy of the mini-game Simple2Dgame_SpaceGirl.
  2. In the Hierarchy panel, add a new UI Image object (Create | UI | Image). Rename it Image-star-icon.
  3. Select Image-star-icon in the Hierarchy...

Displaying multiple pickups of the same object with text totals

When several items of the same type have been picked up, often the simplest way to convey what is being carried to the user is to display a text message showing the numeric total of each item type being carried, as shown in the following screenshot. In this recipe, the total number of stars collected is displayed using a UI Text object.

Displaying multiple pickups of the same object with text totals

Getting ready

This recipe assumes you are starting with project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter. The font you need can be found in folder 1362_02_02.

How to do it...

To display inventory total text for multiple pickups of same type of object, follow these steps:

  1. Start with a new copy of the mini-game Simple2Dgame_SpaceGirl.
  2. Add a UI Text object (Create | UI | Text). Rename it Text-carrying-star. Change its text to stars = 0.
  3. Import the provided Fonts folder into your project.
  4. In the Inspector panel, set the font of Text-carrying-star to Xolonium-Bold (folder Fonts...

Displaying multiple pickups of the same object with multiple status icons

If there is a small, fixed total number of an item to be collected rather than text totals, an alternative effective UI approach is to display placeholder icons (empty or greyed out pictures) to show the user how many of the item remain to be collected, and each time an item is picked up, a placeholder icon is replaced by a full color collected icon.

In this recipe, we use grey-filled star icons as the placeholders and yellow-filled star icons to indicate each collected star, as shown in the following screenshot.

Since our UI code is getting a little more complicated, this recipe will implement the MVC design pattern to separate the view code from the core player logic (as introduced at the end of recipe Displaying single object pickups with carrying and not-carrying text).

Displaying multiple pickups of the same object with multiple status icons

Getting ready

This recipe assumes that you are starting with the project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter.

How to...

Introduction


Many games involve the player collecting items or choosing from a selection of items. Examples could be collecting keys to open doors, collecting ammo for weapons, choosing from a collection of spells to cast, and so on.

The recipes in this chapter offer a range of solutions for displaying to the player whether they are carrying an item or not, if they are allowed more than one of an item, and how many they have.

The big picture

The two parts of software design for implementing inventories relate to, first, how we choose to represent the data about inventory items (that is, the data types and structures to store the data) and, secondly, how we choose to display information about inventory items to the player (the UI: User Interface).

Also, whilst not strictly inventory items, player properties such as lives left, health, or time remaining can also be designed around the same concepts that we present in this chapter.

We need to first think about the nature of different inventory...

Creating a simple 2D mini-game – SpaceGirl


This recipe presents the steps to create the 2DSpaceGirl mini-game, on which all the recipes of this chapter are based.

Getting ready

For this recipe, we have prepared the images you need in a folder named Sprites in the 1362_02_01 folder. We have also provided the completed game as a Unity package in this folder named Simple2DGame_SpaceGirl.

How to do it...

To create the simple 2D mini-game Space Girl follow these steps:

  1. Create a new, empty 2D project.

  2. Import supplied folder Sprites into your project.

  3. Convert each sprite image to be of type Sprite (2D and UI). To do this, select the sprite in the Project panel, then, in the Inspector, change choose Sprite (2D and UI) from the drop-down menu Texture Type, and click on the Apply button, as shown in the following screenshot:

  4. Set the Unity Player screen size to 800 x 600: choose the Edit | Project Settings | Player menu, then for option Resolution and Presentation uncheck Default is Full Screen, and set the...

Displaying single object pickups with carrying and not-carrying text


Often the simplest inventory situation is to display text to tell players if they are carrying a single item (or not).

Getting ready

This recipe assumes that you are starting with the project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter. So, either make a copy of that project or do the following:

  1. Create a new, empty 2D project.

  2. Import the Simple2Dgame_SpaceGirl package.

  3. Open scene Scene1 (in the Scenes folder).

  4. Set the Unity Player screen size to 800 x 600 (see the previous recipe for how to do this) and select this resolution in the Game panel the drop-down menu.

  5. Convert each sprite image to be of type Sprite (2D and UI). In the Inspector, choose Sprite (2D and UI) from drop-down menu Texture Type, and click on the Apply button.

For this recipe, we have prepared the font you need in a folder named Fonts in the 1362_02_02 folder.

How to do it...

To display text to inform the user about the status of carrying...

Displaying single object pickups with carrying and not-carrying icons


Graphic icons are an effective way to inform the player that they are carrying an item. In this recipe, if no star is being carried, a grey-filled icon in a blocked-off circle is displayed; then, after the star has been picked up, a yellow-filled icon is displayed, as shown in the following screenshot.

In many cases, icons are clearer (they don't require reading and thinking about) and can also be smaller onscreen than text messages for indicating player status and inventory items.

Getting ready

This recipe assumes that you are starting with the project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter.

How to do it...

To toggle carrying and not-carrying icons for a single object pickup, follow these steps:

  1. Start with a new copy of the mini-game Simple2Dgame_SpaceGirl.

  2. In the Hierarchy panel, add a new UI Image object (Create | UI | Image). Rename it Image-star-icon.

  3. Select Image-star-icon in the Hierarchy panel...

Displaying multiple pickups of the same object with text totals


When several items of the same type have been picked up, often the simplest way to convey what is being carried to the user is to display a text message showing the numeric total of each item type being carried, as shown in the following screenshot. In this recipe, the total number of stars collected is displayed using a UI Text object.

Getting ready

This recipe assumes you are starting with project Simple2Dgame_SpaceGirl setup from the first recipe in this chapter. The font you need can be found in folder 1362_02_02.

How to do it...

To display inventory total text for multiple pickups of same type of object, follow these steps:

  1. Start with a new copy of the mini-game Simple2Dgame_SpaceGirl.

  2. Add a UI Text object (Create | UI | Text). Rename it Text-carrying-star. Change its text to stars = 0.

  3. Import the provided Fonts folder into your project.

  4. In the Inspector panel, set the font of Text-carrying-star to Xolonium-Bold (folder Fonts)...

Left arrow icon Right arrow icon

Key benefits

  • Built on the solid foundation of the popular Unity 4.x Cookbook, the recipes in this edition have been completely updated for Unity 5
  • Features recipes for both 2D and 3D games
  • Provides you with techniques for the new features of Unity 5, including the new UI system, 2D game development, new Standard Shaders, and the new Audio Mixer

Description

Unity 5 is a flexible and intuitive multiplatform game engine that is becoming the industry's de facto standard. Learn to craft your own 2D and 3D computer games by working through core concepts such as animation, audio, shaders, GUI, lights, cameras, and scripting to create your own games with one of the most important and popular engines in the industry. Completely re-written to cover the new features of Unity 5, this book is a great resource for all Unity game developers, from those who have recently started using Unity right up to game development experts. The first half of the book focuses on core concepts of 2D game design while the second half focuses on developing 3D game development skills. In the first half, you will discover the new GUI system, the new Audio Mixer, external files, and animating 2D characters in 2D game development. As you progress further, you will familiarize yourself with the new Standard Shaders, the Mecanim system, Cameras, and the new Lighting features to hone your skills towards building 3D games to perfection. Finally, you will learn non-player character control and explore Unity 5's extra features to enhance your 3D game development skills.

Who is this book for?

This book is for anyone who wants to explore a wide range of Unity scripting and multimedia features, and find ready-to-use solutions for many game features. Programmers can explore multimedia features, and multimedia developers can try their hand at scripting. *From intermediate to advanced users, from artists to coders, this book is for you, and everyone on your team! *It is intended for everyone who has the basics of using Unity, and a little programming knowledge in C#.

What you will learn

  • Immerse players with great audio, utilizing Unity 5 s audio features including the new Audio Mixer, ambient sound with Reverb Zones, dynamic soundtracks with Snapshots, and balanced audio via Ducking
  • Create better materials with Unity s new, physically-based, Standard Shader
  • Measure and control time, including pausing the game, displaying clocks and countdown timers, and even implementing “bullet timeâ€? effects
  • Improve ambiance through the use of lights and effects such as reflection and light probes
  • Create stylish user interfaces with the new UI system, including power-bars, clock displays, and an extensible inventory system
  • Save and load text and media assets from local or remote sources, publish your game via Unity Cloud, and communicate with websites and their databases to create online scoreboards
  • Discover advanced techniques, including the publisher-subscriber and state patterns, performance bottleneck identification, and methods to maximize game performance and frame rates
  • Control 2D and 3D character movement, and use NavMeshAgents to write NPC and enemy behaviors such as seek, flee, flock, and waypoint path following

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 05, 2015
Length: 570 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391881
Languages :
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 05, 2015
Length: 570 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391881
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 ₱260 each
Feature tick icon Exclusive print discounts
$279.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 ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 8,420.97
Unity 5.x Cookbook
₱3112.99
Unity UI Cookbook
₱2806.99
Unity 5  Game Optimization
₱2500.99
Total 8,420.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Core UI – Messages, Menus, Scores, and Timers Chevron down icon Chevron up icon
2. Inventory GUIs Chevron down icon Chevron up icon
3. 2D Animation Chevron down icon Chevron up icon
4. Creating Maps and Materials Chevron down icon Chevron up icon
5. Using Cameras Chevron down icon Chevron up icon
6. Lights and Effects Chevron down icon Chevron up icon
7. Controlling 3D Animations Chevron down icon Chevron up icon
8. Positions, Movement and Navigation for Character GameObjects Chevron down icon Chevron up icon
9. Playing and Manipulating Sounds Chevron down icon Chevron up icon
10. Working with External Resource Files and Devices Chevron down icon Chevron up icon
11. Improving Games with Extra Features and Optimization Chevron down icon Chevron up icon
12. Editor Extensions 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 Full star icon Half star icon 4.8
(17 Ratings)
5 star 88.2%
4 star 5.9%
3 star 0%
2 star 5.9%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




real7a May 06, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's a good practical book on Unity game development and in the real world nowadays practice goes to production is very fast :) I've started to read it half a Year ago and started with several games and VR projects very fast. So the review is partial and delayed and anyway :)In short it's strongly recommended to jump start and get some vision of the landscape of Unity development.The book is organized as a cookbook as titled "Unity 5.x Cookbook" and it's the series of tutorial lessons actually. Some of lessons are easy and kind of artificial and they are used to show core concepts and lead to real useful tasks.I liked the tutorial of map radar for the shooter game. I made it and even submitted errata that was accepted.There are a lot of more useful lessons there. If You have time to learn it's very good addition to Unity tutorials and official Unity documentation.
Amazon Verified review Amazon
Nicole.Garrow Jan 02, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very helpful in game making!
Amazon Verified review Amazon
ruben Dec 26, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Unity 5.x Cookbook By Ruben Oliva RamosI liked this book, it has a big deal that I could understand the objective of the book, I understood all the chapters, The book has a new content that we can develep our own development.This is an excelent book, because covers my needs in game programming.Ruben
Amazon Verified review Amazon
Tim Crothers Dec 23, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love that this book is jam packed with practical and useful examples. All of the example code, images and other files are a free download. Seems to me that just finding one or two of the recipes useful would justify the cost of the book. In my case I was able to adapt several of them for inclusion in my projects and gained a ton of value.
Amazon Verified review Amazon
Adam Maksym May 29, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Helpful Info..
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.