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 Game Development Scripting
Unity Game Development Scripting

Unity Game Development Scripting: Write efficient C# scripts to create modular key game elements that are usable for any kind of Unity project

eBook
€20.98 €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

Unity Game Development Scripting

Chapter 2. GUI Time

In video games, the GUI is one of the most important parts of the game. It's where you see how much health you have, what level you are at, how much gold you're carrying, and so on. It's how you gather information on your character and the world you are in.

In this chapter, we'll be covering the following topics:

  • Both 2D and 3D GUI elements
  • How to create GUI buttons
  • How to create a 2D health bar
  • Tracking the player's level by using a GUI label
  • Using two GUI boxes to make an experience bar
  • Creating a 3D health bar
  • Showing 3D damage reports
  • Showing enemy name tags

A traditional 2D UI

To start our GUI programming, we'll create some buttons, a health bar, a level counter, and an experience counter. All of these are common in a variety of video games and are key elements to game design.

Setting up our scene

Since in this part of the chapter we will be dealing with 3D space, we'll need to set up a scene to test with. We'll only need a basic test level, so create a new scene and name it Chapter 2. Add a cube or plane for the floor, a directional light, a GameObject for our enemy, and two quads. This is what my scene looks like:

Setting up our scene

Set the two quads in the same position just above your enemy object and rotate one of them by 180 degrees so that the two quads look like one object. Drag one of the quads onto the other, making a parent-child object. Now that our scene is ready, let's get to the scripting.

Housing our 2D UI

Before we start creating our 2D UI, let's make the script to house it all. Create a new C# script and name it GUI_2D...

Housing our 3D UI

We will follow similar steps when housing our 3D UI as we did when housing our 2D UI. Create a new script and call it GUI_3D.

Creating a 3D health bar

Our first step will be to add our variables needed for the health bar:

public float currentHealth = 100;
public float maximumHealth = 100;
float currentBarLength;
public Transform HealthBar;
Vector3 OrigScale;

The first three variables are what we'll use to calculate our health bar. The Transform variable is how we'll interact with our 3D object that's being used as our health bar. The Vector3 variable is a reference point for when we scale the bar.

Our next step will be to add a Start() function. We'll use the Start() function to set the OrigScale variable:

void Start()
{
  OrigScale = HealthBar.transform.localScale;
}

We set OrigScale before we do anything else in the health bar. This is what we'll use as a reference point for the health bar. Next, we'll create our Update() function:

void Update(...

Summary

In this chapter, you learned a few ways to create a GUI. First, you started off by learning the traditional way of creating the GUI by making buttons, bars, and text. Then, we switched gears and learned how to make a 3D GUI by making 3D health bars, 3D damage reports, and 3D name tags.

In the next chapter, you will learn how to make a few different classes for in-game items. First, we'll create a class so that items will affect the player, the next class will allow items to affect other objects on touch, and the final class will be created for projectiles. All of these can be used for the player, enemies, or environment objects.

Left arrow icon Right arrow icon

Description

The intuitive and powerful Unity game engine is one of the most widely used and best loved packages for game development. Unity scripting is an essential but challenging skill to master in order to create custom game elements. Learning modular scripting allows you to rewrite as little code as possible as you deploy your scripts to multiple projects and work easier, quicker, and more efficiently than before. In each chapter of this book, you'll learn how to script new game elements. Beginning with making custom controls for the keyboard and mouse, as well as the Xbox 360 Controller, you'll then get to grips with more complex systems such as inventory, data saving, and artificial intelligence. As you create these elements, you'll also learn how to make your scripts simpler and easy to use. This will allow drag-and-drop deployment, which is to be used by designers and nonprogrammers. Finally, you'll combine all of your newfound skills to create your own complete game project.
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 22, 2014
Length: 202 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553631
Vendor :
Unity Technologies
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 Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Publication date : Dec 22, 2014
Length: 202 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553631
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 73.98
Unity Game Development Scripting
€36.99
Unity Game Development Blueprints
€36.99
Total 73.98 Stars icon
Banner background image

Table of Contents

11 Chapters
1. Interactive Input Chevron down icon Chevron up icon
2. GUI Time Chevron down icon Chevron up icon
3. Expandable Item Classes Chevron down icon Chevron up icon
4. Inventory Chevron down icon Chevron up icon
5. Enemy and Friendly AIs Chevron down icon Chevron up icon
6. Keeping Score Chevron down icon Chevron up icon
7. Creating Save and Load Systems Chevron down icon Chevron up icon
8. Aural Integration Chevron down icon Chevron up icon
9. Game Settings Chevron down icon Chevron up icon
10. Putting It All Together 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.1
(7 Ratings)
5 star 42.9%
4 star 28.6%
3 star 28.6%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




MR B BYFORD Feb 16, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Hugely useful overview of various game design has its and how they can work in unity.Got this after the 2d game development in unity book, and was please at how it built on my knowledge and didn't spell things that I already knew. Not for absolute beginners.
Amazon Verified review Amazon
Mário Freitas Mar 01, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is written in very concise and simple to understand way, guiding the reader the whole way to actually create a simple working game, and covering most topics on game development scripting.I would highly recommend this book to people who are new to Unity scripting and to those who would like to learn more about how to structurally and conceptually organize a game from the point of view of game development scripting.The book also offers standard approaches to the implementation of features that are present and required in any game.
Amazon Verified review Amazon
Peter Matthew Apr 30, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As a Lecturer in Games Development I am always on the lookout for books that can help my students improve their understanding of both c# and Unity3d. This book provides a lot of very good tutorials and explanations that cover a variety of subjects within the games development area. The sections are clearly written and provides good examples of the code being discussed. After discussing the book with some of my second year students they described it as “very helpful” and “easier to understand than a lot of other books”.Some criticisms of the book are that the sections are a little abstract in places jumping from topic to topic and it relies on a previous understanding of coding knowledge to get the most out of it, therefore lending itself more to an intermediate or advanced user.Regardless the author does an excellent job of explaining useful scripts that most games developers will want to include: such as re -bindable controller settings and user interface development, therefore providing the reader with a practical set of scripting examples.I would recommend this book for anyone wanting to improve their understanding of Unity scripting and my department is now using this book as part of our essential reading list for all second year games programmers.
Amazon Verified review Amazon
Robert L. Dixon Feb 07, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I read a lot of books about Unity and C# since I'm always trying to up my game, so to speak. This book has some good sections but overall doesn't cohere as well as it could. But it could be useful for people with some Unity experience who are looking for specific techniques.It jumps right into scripting individual subsystems without talking about what kind of game is going to be built and how everything will fit together. Later on you learn the example game is an RPG-style game with characters, weapons and objects. It would have been nice to know this ahead of time, because some of the chapters are only relevant to this type of game.Overall this is more like a "cookbook" of various recipes, as opposed to a step-by-step guide to building a real game. If you already have some experience coding C# in Unity, and you are interested in some of the chapter topics, you should find the book useful.Here's a brief rundown on some specific chapters:* The first chapter on Interactive Input present a nice technique for switching among input control schemes. However there's an emphasis on supporting the XBox 360 controller which might not be relevant to a lot of developers.* The GUI chapter relies a little too heavily on the old, mostly obsolete Unity GUI approach, so it is not too useful in the post-Unity-4.6 world.* The Expandable Item Classes chapter presents a nice starting point for structuring in-game items that affect player characters and objects.* The chapter on AI covers two different AI topics: simple enemy decision-making (switching an enemy object among Idle, Guard, Combat, Flee states), and pathfinding. The pathfinding section gives a good introduction to Unity's NavMesh system, which is not covered in many other books. The example for this chapter uses the AI scripts to animate some freely-available skeleton models (from the Asset Store) around an environment.* The chapter about Keeping Score on the other hand presents some real brute-force coding with hard-coded achievement thresholds and such. There are better and simpler ways to code this, so I would give this chapter a pass.* The same could be said for the next chapter, which covers Saving and Loading Data. It uses XML, which is generally heavier and harder to work with than JSON, and again shows some brute-force coding that might not hold up well over time.* Chapter 8 deals with audio and offers some simple, reusable classes for managing and playing sounds.* The final chapter, "Putting It All Together," builds a simple game by assembling all the subsystems from previous chapters. It's very nice to see all the parts working together at the end. This chapter could have been fleshed out a bit more. It would have been nice to have an overview, like a diagram, of how all the subsystems fit together, rather than a step-by-step "now add this, now add this" sequence. In fact this kind of overview would have been really useful prior to Chapter 1, so the reader can go into the rest of the book knowing what to expect.Overall there are a lot of things to learn from this book. In addition there is a nice emphasis on play-testing at the end of each chapter, with suggestions of ways to enhance the examples in your own games. But it's not a complete guide to building your own games in Unity.
Amazon Verified review Amazon
Matthew Feb 09, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Bottom line up front, this book is a great tool to keep in your kit bag. With a basic knowledge of programming and Unity, I started an indie game development company with several game ideas in mind. What I quickly discovered was, like most things in life, there are multiple ways to accomplish a single task within Unity. This created a challenge I hadn’t planned for. Originally I thought it would be difficult to find the right literature to help me achieve my goal, but instead I found that I was inundated with information. I recently came across “Unity Game Development Scripting” by Kyle D'Aoust and became quite pleased with what I had found. The book is laid out in a very efficient manner covering all the major aspects of creating a game. The first chapter deals with the most important aspect, defining user input. It lays out two options one for keyboards and the other for an Xbox controller. At first glance the reader may be tempted to think this doesn’t apply to me because I’m not developing for those platforms. This may be true, but if the reader looks deeper they will start to see how the techniques used in the book can transfer into other projects. The process the writer took to define different aspects and requirements for control are useful when designing the controls for all games. Chapters 5 and 7 are also great examples of a situation where the techniques used are beneficial to any reader attempting to develop a game in Unity. I have personally struggled with scripting enemy artificial intelligence in a 2D platformer game and have waffled between different techniques. After reading chapter 5, I was able to add a more efficient solution to my games even though the writer is referencing 3D game creation. In addition, chapter 7 answers the question of saving game progress. When I first started developing games this task perplexed me, but “Unity Game Development Scripting” by Kyle D'Aoust does an excellent job of defining C# scripting that accomplishes the task. Though I was overall happy with this book, there was one point of contention I had with the way it was written. The author provides numerous coding examples written in C# throughout each chapter. He does a good job giving a description after each block of coding, but I found it to be rather taxing on the mind to connect the explanations with the code previously read. A better way to accomplish this would have been to add comments directly into the code itself. This would have personally helped me better follow the readings. Again, this book is an excellent tool for any developer to have. If you don’t have an intermediate understanding of programming and Unity, you will probably find this book to be frustrating as it is not a tutorial based piece of work. But if you are looking for a resource to help refine and/or add to your own techniques for game development then this is the right place to start.
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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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