Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
€8.99 €29.99
Paperback
€36.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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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.

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

Billing Address

Product Details

Publication date : Dec 22, 2014
Length: 202 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553648
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

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.