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
S$36.99 S$52.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (6 Ratings)
eBook Nov 2014 318 pages 1st Edition
eBook
S$36.99 S$52.99
Paperback
S$66.99
Subscription
Free Trial
Arrow left icon
Profile Icon John P. Doran
Arrow right icon
S$36.99 S$52.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (6 Ratings)
eBook Nov 2014 318 pages 1st Edition
eBook
S$36.99 S$52.99
Paperback
S$66.99
Subscription
Free Trial
eBook
S$36.99 S$52.99
Paperback
S$66.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
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 : 9781783553662
Vendor :
Unity Technologies
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

Product Details

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

Frequently bought together


Stars icon
Total S$ 133.98
Unity Game Development Scripting
S$66.99
Unity Game Development Blueprints
S$66.99
Total S$ 133.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

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.