Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Unity Game Development Blueprints
Unity Game Development Blueprints

Unity Game Development Blueprints: Explore the various enticing features of Unity and learn how to develop awesome games

Arrow left icon
Profile Icon John P. Doran
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (6 Ratings)
Paperback Nov 2014 318 pages 1st Edition
eBook
$19.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon John P. Doran
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (6 Ratings)
Paperback Nov 2014 318 pages 1st Edition
eBook
$19.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$19.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Unity Game Development Blueprints

Chapter 2. Creating GUIs

A Graphical User Interface (GUI) is way the players interact with your games. You've actually been using a GUI in the previous chapter (the Unity Editor) and also when interacting with your operating system. Without a GUI of some sort, the only way you'd be able to interact with a computer is a command prompt such as DOS or UNIX.

When working on GUIs, we want them to be as intuitive as possible and only contain the information that is pertinent to the player at any given time. There are people whose main job is programming and/or designing user interfaces and there are college degrees on the subject as well. So, while we won't talk about everything that we have to work with on GUIs, I do want to touch on the aspects that should be quite helpful when working on your own projects in the future.

Project overview

Over the course of this chapter, we will be expanding on our twin-stick shooter by adding additional UI elements that will include a main menu, a pause menu, and an options menu and will give us the ability to restart our project. This chapter uses the UnityGUI system that existed before Unity 4.6. Even though the new system does have its advantages, the old system is still quite useful to learn. It's still the only way to create UI elements for the Unity Editor (which you can use to create plugins that you can sell on the Asset Store), and it has a much larger amount of documentation out there to help new users.

Note

If you are interested in learning specifically about the new GUI system, please check out Chapter 9, Creating GUIs Part 2 – Unity's New GUI System, where I talk about specific cases in which you'd want to use the new system.

Your objectives

This project will be split into a number of tasks. It will be a simple step-by-step process from beginning...

Project setup

At this point, I have assumed that you have a fresh installation of Unity, and have started it up. You need to perform the following steps:

  1. Open the previous project. Now, let's first create a new scene by navigating to File | New Scene. With the new scene created, save it by navigating to File | Save Scene. Name it Main_Menu.unity and save it inside your Scenes folder.
  2. Let's first grab the background from our previous level so that we do not need to create it once again. To do that, double-click on the scene you created in the first chapter. Left-click on the Background object in the Hierarchy view and navigate to Edit | Copy. Go back to your Main_Menu scene and paste it into the world by navigating to Edit | Paste:
    Project setup

    Unity has an inbuilt GUI functionality through the UnityGUI system that allows us to create interfaces through scripts.

    Note

    Unless you are using Unity 4.6 or later, Unity doesn't have an included visual GUI development system, but you can find tools...

Customizing the GUI

While it is great that Unity provides us with all of this functionality to save us time in creating elements, the actual aesthetics leaves a little to be desired. Thankfully, UnityGUI allows us to customize the appearance of our controls by making use of GUIStyle, which is an optional third parameter to our control functions. If we do not specify a GUIStyle parameter, Unity's default will be used, which is what we experienced last time. This can work fine while testing something out. However, since we're trying to create a polished and complete project, we're going to create one of our own by performing the following steps:

  1. Open up the MainMenuGUI script file and modify the function to accommodate the changes in bold:
    using UnityEngine;
    using System.Collections;
    
    public class MainMenuGUI : MonoBehaviour {
      public int buttonWidth = 100;
      public int buttonHeight = 30;
      public GUIStyle titleStyle;
      public GUIStyle buttonStyle;
    
      void OnGUI() 
      {
        ...

Pausing the game

Now that we have started on our main menu, let's add some additional GUI functionality to our game, adding in the ability to pause our game and restart it. However, before we do that, let's take a look at some stuff we can do to make our lives easier when it comes to customization:

  1. We also want to make these buttons have the same appearance as the stuff we've done previously. However, instead of having to set these properties every single time, we can use something called a GUISkin to change what the default controls will appear like by setting the GUI.skin property to a new one.
  2. Create a GUISkin by navigating to Project | Create | GUI Skin, and rename the skin to GUISkin. Open up the Button tab, and you should notice it looks exactly the same as the previous section. Do those same changes that we did previously here, but change the Text Color property to black by clicking on the current color and then selecting black from the color cube that pops up. Alternatively...

Restarting the game

There may come a time in a game when a player makes a mistake and would like to restart the level in the game they're currently playing. If you prepared your project ahead of time like we have, it's actually quite easy to get this functionality placed into your game. With that being said, let's implement that functionality now! We will perform the following steps:

  1. Open up the PauseMenu script and add the following highlighted code:
    GUILayout.BeginHorizontal();
    
        if (GUILayout.Button ("Resume")) 
        {
          //resume the game
          isPaused = false;
        }
    
        if (GUILayout.Button ("Restart")) 
        {
          Application.LoadLevel(Application.loadedLevelName);
        }
        GUILayout.EndHorizontal();
    
  2. Once finished, save your file and move back into Unity and play the game! The following screenshot depicts the game screen:
    Restarting the game

Simple enough! We've now added a new button to our menu and when we click on it, we load the currently loaded level...

Project overview


Over the course of this chapter, we will be expanding on our twin-stick shooter by adding additional UI elements that will include a main menu, a pause menu, and an options menu and will give us the ability to restart our project. This chapter uses the UnityGUI system that existed before Unity 4.6. Even though the new system does have its advantages, the old system is still quite useful to learn. It's still the only way to create UI elements for the Unity Editor (which you can use to create plugins that you can sell on the Asset Store), and it has a much larger amount of documentation out there to help new users.

Note

If you are interested in learning specifically about the new GUI system, please check out Chapter 9, Creating GUIs Part 2 – Unity's New GUI System, where I talk about specific cases in which you'd want to use the new system.

Your objectives

This project will be split into a number of tasks. It will be a simple step-by-step process from beginning to end. Here is...

Project setup


At this point, I have assumed that you have a fresh installation of Unity, and have started it up. You need to perform the following steps:

  1. Open the previous project. Now, let's first create a new scene by navigating to File | New Scene. With the new scene created, save it by navigating to File | Save Scene. Name it Main_Menu.unity and save it inside your Scenes folder.

  2. Let's first grab the background from our previous level so that we do not need to create it once again. To do that, double-click on the scene you created in the first chapter. Left-click on the Background object in the Hierarchy view and navigate to Edit | Copy. Go back to your Main_Menu scene and paste it into the world by navigating to Edit | Paste:

    Unity has an inbuilt GUI functionality through the UnityGUI system that allows us to create interfaces through scripts.

    Note

    Unless you are using Unity 4.6 or later, Unity doesn't have an included visual GUI development system, but you can find tools on the Unity Asset...

Customizing the GUI


While it is great that Unity provides us with all of this functionality to save us time in creating elements, the actual aesthetics leaves a little to be desired. Thankfully, UnityGUI allows us to customize the appearance of our controls by making use of GUIStyle, which is an optional third parameter to our control functions. If we do not specify a GUIStyle parameter, Unity's default will be used, which is what we experienced last time. This can work fine while testing something out. However, since we're trying to create a polished and complete project, we're going to create one of our own by performing the following steps:

  1. Open up the MainMenuGUI script file and modify the function to accommodate the changes in bold:

    using UnityEngine;
    using System.Collections;
    
    public class MainMenuGUI : MonoBehaviour {
      public int buttonWidth = 100;
      public int buttonHeight = 30;
      public GUIStyle titleStyle;
      public GUIStyle buttonStyle;
    
      void OnGUI() 
      {
        //Get the center...
Left arrow icon Right arrow icon

Description

If you want to build enticing projects with Unity, this book is for you. Readers who are familiar with the basics of how to create simple projects in Unity will have an easier time.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 11, 2014
Length: 318 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553655
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 11, 2014
Length: 318 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553655
Vendor :
Unity Technologies
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 $5 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 97.98
Unity Game Development Scripting
$48.99
Unity Game Development Blueprints
$48.99
Total $ 97.98 Stars icon

Table of Contents

10 Chapters
1. 2D Twin-stick Shooter Chevron down icon Chevron up icon
2. Creating GUIs Chevron down icon Chevron up icon
3. Side-scrolling Platformer Chevron down icon Chevron up icon
4. First Person Shooter Part 1 – Creating Exterior Environments Chevron down icon Chevron up icon
5. First Person Shooter Part 2 – Creating Interior Environments Chevron down icon Chevron up icon
6. First Person Shooter Part 3 – Implementing Gameplay and AI Chevron down icon Chevron up icon
7. Creating Save Files in Unity Chevron down icon Chevron up icon
8. Finishing Touches Chevron down icon Chevron up icon
9. Creating GUIs Part 2 – Unity's New GUI System 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 Empty star icon 4
(6 Ratings)
5 star 50%
4 star 33.3%
3 star 0%
2 star 0%
1 star 16.7%
Filter icon Filter
Top Reviews

Filter reviews by




MS HURST Dec 05, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I had already watched a lot of the little tutorials explaining various concepts in Unity on the official website and although they were good, not using them in an actual project meant I didn't get a chance to see how things all work together. That is where this book comes in.The book comprises of 3 main projects (Demo videos of which are available on youtube from the author, well worth a look if you want to see what you will be making). These projects are:1) 2D Shooter (Essentially a geometry-wars type game)2) 2D Platformer using 3D assets and physics3) 3D First person "horror" gameThere are also chapters on useful concepts such as GUI (You are shown how to make a main menu, pause menu and options screen for your first project), a 2D level editor for the second project and saving and loading progress for the thirdThe projects are excellent in that they give you enough information to make a basic playable game, and then task you with adding some extra features to it, such as adding in controller capabilities for the first projectA huge bonus with this book is that it also includes a chapter on the new GUI system introduced in the Unity 4.6 beta. It is the final chapter in the book and as such doesn't have to be used if you're not using the beta version (The proper GUI chapter still uses the old system) but very handy for people who want to get ahead of the curve with the new featuresAll in all I would hugely recommend this book both to people who have opened Unity once and been completely baffled and people who have a basic understanding and need to take it to the next level in order to create full projects
Amazon Verified review Amazon
steve Nov 08, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent way to learn how to build and code games in Unity.
Amazon Verified review Amazon
Thom Dec 21, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
After reading many, many, many books about Unity development, I honestly believe THIS IS THE BEST one!It is complete yet guides you through carefully; several projects from 2D side-scroller to a fully-implemented First Person Shooter.Along the way, details on GUI menus, Environments, and other sophisticated topics are introduced appropriately.
Amazon Verified review Amazon
Chev Dec 18, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The book has a nice pace for beginners, it gives explanations when needed and moves at a nice speed. I do wish the author (John Doran) went into more detail as to why he chose to do certain things a certain way instead of a perform these steps exactly like this approach. Following along with the book using Unity you do get to make the games from the book but not a whole lot of explaining as to why we need to do things a certain way. So creating your own game from scratch will prove to be problematic for those without prior experience. The chapter on UI is now a little dated due to the new UI system in Unity 4.6 but thankfully there is another chapter later in the book going over the new UI system in Unity 4.6. Kudos for the Author on providing information on both UI systems for the readers. The chapters on creating a First Person Shooter are my favorite, there was a lot of thought and effort into how best to explain things to a beginner. Creating Exterior Environments actually covers a lot of Unity tools but its doesn’t seem crammed or rushed. It walks you thru creating outside environments and the tools you will use in such a way that you forget you are learning and just get immersed into the FPS environment you are creating. Also props to the author for having us to a nighttime scene, I always see examples and tutorials on daytime environments but none on nighttime environments. In my opinion its much harder to get the realism and general creepiness of a nighttime forrest environment then some sunny blue sky perfect green grass environments most books teach you with. Now would be a good time to note that the author takes time to explain the different roles when it comes to game development so the reader can see the different areas involved. One chapter we are creating the outside environment as an environmental artist and the next we are creating interiors as a level designer. its great to see the different roles and how everything comes together. The interior environments chapter goes over modular level design with tiles which is what many of the larger AAA games use. Its a topic that is hard to find good information on but the author nails it in chapter 5. The rest of the FPS chapters go over AI, state machines, saving and some other great topics. Like I said previously, the chapters on creating a First Person Shooter were my favorite. There are so many good nuggets of info in those chapters I found myself reading the over and over trying to catch everything.Overall Unity Game Development Blueprints is a good book that covers a lot of topics and concepts of game development. This book shows the correct way of game development that can be used in real world AAA games. It doesn’t do what most books do and show you just a watered down way leaving you with many questions and lack of understanding of how the AAA titles and developers work. John Doran has over 10 years in the industry and it really shows in this book. I would easily recommend this to anyone wanting to learn the proper way to develop games just like the big guys
Amazon Verified review Amazon
W Boudville Dec 21, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The screen shots in the book of the Unity development platform show a comprehensive array of options. All of which you can use to write a compelling interactive game. The book walks through extended examples that give source code snippets. So while you are interested in how the end user would play a game, the book describes another type of interplay. Between using the Unity GUI and the resultant source code as well as (of course!) the images seen by a player.The presumption is of little prior game writing. The easiest way to see this might be in chapter 3, where the switch statement is introduced and explained. This is pretty basic stuff to anyone who has programmed in any language! What is happening is that the book is pitched towards a reader who has a good [presumably] game idea to storyboard, but perhaps has little actual programming nous.The chapters end with a section called Challenges. These have suggestions about how to extend the example in each chapter. If this is indeed new programming to you, good advice might be to take up those suggestions. You can learn more by doing. Deepens your knowledge of using Unity.
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 included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.