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

Unity 3.x Game Development Essentials: If you have an idea for a game but lack the skills to create it, this book is the perfect introduction. There’s lots of handholding through all the essentials, culminating in the building of a full 3D game.

eBook
€32.99
Paperback
€41.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
Table of content icon View table of contents Preview book icon Preview Book

Unity 3.x Game Development Essentials

Chapter 2. Prototyping and Scripting Basics

When starting out in game development, one of the best ways to learn the various parts of the discipline is to prototype your idea. Unity excels in assisting you with this, with its visual scene editor and public member variables that form settings in the Inspector. To get to grips with working in the Unity editor, we'll begin by prototyping a simple game mechanic using primitive shapes and basic coding.

In this chapter, you will learn about:

  • Creating a New Project in Unity

  • Importing Asset packages

  • Working with game objects in the Scene view and Hierarchy

  • Adding materials

  • Writing C Sharp (C#) and Javascript

  • Variables, functions, and commands

  • Using the Translate() command to move objects

  • Using Prefabs to store objects

  • Using the Instantiate() command to spawn objects

Your first Unity project


As Unity comes in two main forms—a standard, free download and a paid Pro developer license, we'll stick to using features that users of the standard free edition will have access to.

If you're launching Unity for the very first time, you'll be presented with a Unitydemonstration project. While this is useful to look into best practices for the development of high-end projects, if you're starting out, looking over some of the assets and scripting may feel daunting, so we'll leave this behind and start from scratch!

In Unity go to File | New Project and you will be presented with the Project Wizard (Mac version shown); from here select the Create New Project tab .

Note

Be aware that if at any time you wish to launch Unity and be taken directly to the Project Wizard, then simply launch the Unity Editor application and immediately hold the Alt key (Mac and PC). This can be set to the default behavior for launch in the Unity Preferences.

Click the Set button and choose...

A basic prototyping environment


To create a simple environment, in which to prototype some game mechanics, we'll begin with a basic series of objects with which to introduce gameplay that allows the player to aim and shoot at a wall of primitive cubes.

When complete, your prototyping environment will feature a floor comprised of a cube primitive, a main camera through which to view the 3D world and a Point Light setup to highlight the area where our gameplay will be introduced. It will look something like this:

Setting the scene

As all new scenes come with a Main Camera object by default, we'll begin by adding a floor for our prototyping environment.

On the Hierarchy panel, click the Create button, and from the drop-down menu, choose Cube. The items listed in this drop-down menu can also be found in the GameObject | Create Other top menu. You will now see an object in the Hierarchy panel called a Cube. Select this and press Return (Mac) /F2 (PC) or double-click the object name slowly (both...

Introducing scripting


To take your first steps into programming, we will look at a simple example of the same functionality in both C Sharp(C#) and Javascript, the two main programming languages used by Unity developers. It is also possible to write Boo based scripts, but these are rarely used outside of those with existing experience in that language.

Note

To follow the next steps you may choose either Javascript or C#, then in the rest of this book continue with the chosen language your prefer.

To begin, click the Create button on the Project panel, then choose either Javascript or C# Script.

Your new script will be placed into the Project panel named NewBehaviourScript, and show an icon of a page with either JS or C# written on it. When selecting your new script, Unity offers a preview of what is in the script already, in the view of the Inspector, and an accompanying Edit button that when clicked will launch the script into the default script editor—Monodevelop. You can also launch a script...

Understanding Translate


To actually use these variables to move an object, we will use the Translate command. When implementing any piece of scripting, you should make sure you know how to use it first.

Translate is a command which is part of the Transform class: http://unity3d.com/support/documentation/ScriptReference/Transform.html.

This is a class of information that stores the position, rotation, and scale properties of an object, and also functions that can be used to move and rotate the object.

The expected usage of Translate is as follows:

Transform.Translate(Vector3);

The use of Vector3 here means that Translate is expecting a piece of Vector3 data as it's the main argument—Vector3 data is simply information that contains a value for the X, Y, and Z coordinates; in this case coordinates to move the object by.

Implementing Translate

Now let's implement the Translate command by taking the h and v input values that we have established, placing them into Vector3 within the command.

C# and...

Testing the game so far


In Unity you can play test at any time, provided there are no errors in your scripts. If there are, Unity will ask you to fix all errors before allowing you to enter the Play Mode.

Once all errors are fixed—this will be signified by an empty or cleared Console bar at the bottom of the Unity interface. The Console bar represents the most recent entry into the Unity console. You can check this by choosing Window | Console (shortcut Ctrl + Shift + C [PC] Command-Shift + C [Mac]) from the top menu. All the errors will be listed in red, and double-clicking on the error will take you to the part of the script that will be causing the issue described. Most errors are often a forgotten character or simple misspelling, so always double check what you have written as you go.

If your game is free of errors, click the Play button at the top of the screen to enter the Play Mode. You will now be able to move the MainCamera object around by using the arrow keys—Up, Down, Left, and...

Storing with prefabs


As we wish to fire this projectile when the player presses a key, we do not want the projectile to be in the scene by default, but instead want it to be stored and created when the key is pressed. For this reason we will store the object as a prefab, and use our script to instantiate (that is, create an instance of) it at the precise moment a key is pressed.

Note

Prefabs are Unity's way of storing GameObjects that have been set up in a particular way; for example, you may have configured an enemy soldier with particular scripts and properties that behaves a certain way. You can store this object as a prefab and instantiate it when necessary. Similarly you might have a differing soldier that behaves differently, this might be a different prefab, or you might create an instance of the first, and adjust settings in the soldier's components, making him faster or slower upon instantiation for example; the Prefab system gives you a lot of flexibility in this regard.

Click the...

Using Instantiate() to spawn objects


Now within this IF statement—meaning after the opening { and before the closing }, put the following line:

C#:

Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;

Javascript:

var instance: Rigidbody = Instantiate(bullet, transform.position, transform.rotation);

Here we are creating a new variable named instance. Into this variable we are storing a reference to the creation of a new object that is of type Rigidbody.

The Instantiate commands requires three pieces of information namely, Instantiate(What to make, Where to make it, a rotation to give it);

So in our example, we are telling our script to create an instance of whatever object or prefab is assigned to the bullet public member variable and that we would like it to be created using the values of position and rotation from the transform component of the object this script is attached to—the Main Camera. This is why you will often see transform.position written...

Summary


Congratulations! You have just created your first Unity prototype.

In this chapter, you should have become familiar with with the basics of using the Unity interface, working with Game Objects, components, and basic scripting. This will hopefully act as a solid foundation upon which to build further experience in Unity game development.

Now you might want to relax a little and take time to play your prototype or even create one of your own based on what you have learned. Or you may just be eager to learn more; if so, keep reading!

Let's move on to the main game of this book, now that you are a little more prepared on some of the basic operations of the Unity development.

In the next chapter, we will begin to create a game called Survival Island. In this, you will learn how to use the Terrain tools to create a tropical island, complete with its own volcano! Once you have created your island, you'll add a player character prefab and take a stroll around your newly created tropical paradise...

Left arrow icon Right arrow icon

Key benefits

  • Kick start your game development, and build ready-to-play 3D games with ease.
  • Understand key concepts in game design including scripting, physics, instantiation, particle effects, and more.
  • Test & optimize your game to perfection with essential tips-and-tricks.
  • Written in clear, plain English, this book takes you from a simple prototype through to a complete 3D game with concepts you‚Äôll reuse throughout your new career as a game developer.
  • Learn game development in Unity version 3 and above, and learn scripting in either C# or JavaScript

Description

Game Engines such as Unity are the power-tools behind the games we know and love. Unity is one of the most widely-used and best loved packages for game development and is used by everyone, from hobbyists to large studios, to create games and interactive experiences for the web, desktop, mobile, and console. With Unity’s intuitive, easy to learn toolset and this book – it’s never been easier to become a game developer. Taking a practical approach, this book will introduce you to the concepts of developing 3D games, before getting to grips with development in Unity itself – prototyping a simple scenario, and then creating a larger game. From creating 3D worlds to scripting and creating game mechanics you will learn everything you’ll need to get started with game development. This book is designed to cover a set of easy-to-follow examples, which culminate in the production of a First Person 3D game, complete with an interactive island environment. All of the concepts taught in this book are applicable to other types of game, however, by introducing common concepts of game and 3D production, you'll explore Unity to make a character interact with the game world, and build puzzles for the player to solve, in order to complete the game. At the end of the book, you will have a fully working 3D game and all the skills required to extend the game further, giving your end-user, the player, the best experience possible. Soon you will be creating your own 3D games with ease!

Who is this book for?

If you’re a designer or animator who wishes to take their first steps into game development or prototyping, or if you’ve simply spent many hours sitting in front of video games, with ideas bubbling away in the back of your mind, Unity and this book should be your starting point. No prior knowledge of game production is required, inviting you to simply bring with you a passion for making great games.

What you will learn

  • An understanding of the Unity 3D Engine and game development
  • Write code for game development in either C# or JavaScript
  • Build a 3D island and set of mini-games for your players
  • Incorporate terrains and externally produced 3D models to get your game environment up and running
  • Create player character interactions
  • Combine scripting and animation to transform your static objects into dynamic interactive game elements
  • Add realistic effects to your games by using particle systems
  • Create a stylish and efficient menu, and animate other interface elements
  • Use Lightmapping to make your game environments look more professional
  • Deploy your game to the web and desktop and share it with the wider world for testing and feedback.
Estimated delivery fee Deliver to Slovakia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 20, 2011
Length: 488 pages
Edition : 1st
Language : English
ISBN-13 : 9781849691444
Vendor :
Unity Technologies
Languages :
Concepts :
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
Estimated delivery fee Deliver to Slovakia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Publication date : Dec 20, 2011
Length: 488 pages
Edition : 1st
Language : English
ISBN-13 : 9781849691444
Vendor :
Unity Technologies
Languages :
Concepts :
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 83.98
Unity 3.x Game Development Essentials
€41.99
Learning C# by Developing Games with Unity 3D Beginner's Guide
€41.99
Total 83.98 Stars icon

Table of Contents

13 Chapters
Enter the Third Dimension Chevron down icon Chevron up icon
Prototyping and Scripting Basics Chevron down icon Chevron up icon
Creating the Environment Chevron down icon Chevron up icon
Player Characters and Further Scripting Chevron down icon Chevron up icon
Interactions Chevron down icon Chevron up icon
Collection, Inventory, and HUD Chevron down icon Chevron up icon
Instantiation and Rigidbodies Chevron down icon Chevron up icon
Particle Systems Chevron down icon Chevron up icon
Designing Menus Chevron down icon Chevron up icon
Animation Basics Chevron down icon Chevron up icon
Performance Tweaks and Finishing Touches Chevron down icon Chevron up icon
Building and Sharing Chevron down icon Chevron up icon
Testing and Further Study 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.5
(100 Ratings)
5 star 64%
4 star 27%
3 star 8%
2 star 1%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Michael Mar 26, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you're new to Unity this book is perfect. Very clear instructions. The book teaches you on how to build a game and every chapter takes you to adding new stuff towards completion of the game. I have c# background but the book covers c# and javascript so it's all good. I hope he releases another book for 2013. The author even responds to my emails despite his busy schedule. :-)
Amazon Verified review Amazon
Lelle Nov 03, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good guide to open the nature of the program. Highly recommended, value for the price. Very easy to understand even the most complicated commands/codes of the program.
Amazon Verified review Amazon
Rodrigo Mamao Apr 03, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Unity 3.x Game Development Essentials remains true to the style of the first version but with improved explanations on main topics and updated information about the features added to Unity since then.It is a good book for those who wish a step by step introduction to Unity, from prototyping to optimization. It uses both C# and Javascript, so you can follow the one you feel more comfortable with. Since Unit is really an environment and not a language, information about the user interface is helpful when you are new to it. The book use screenshots where it is important, without overusing it. An additional bonus goes to small tip boxes along the text, with helpful insights. Details like this make all the difference.
Amazon Verified review Amazon
Eclectus Nov 08, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written, good structure, and available on kindle. All code examples available in C# which is good (javascript is there too, for all of them). Have not found any mistakes in the book.
Amazon Verified review Amazon
William Smith Jul 11, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This was a great intro to Unity. Project built throughout had you using much of the tool and explaining multiple ways of accomplishing tasks. Also appreciated author taking the time to go through 2-3 ways of doing something and then showing why one is better than the other. After reading I feel like I can better understand how to use the tool to accomplish what I want and can now get much more out of online tutorials or other books on game development.Appreciated that Unity 4.0 package was available on authors web site.Using C# I did not find any errors with code in book (js looks like it has a few via the notes on authors site). When something did go wrong it was only because I missed a step or did not set something correctly. Also got Kindle edition and read on second computer, no issues with fonts/colors/etc...Will you be building awesome games after reading? Of course not, but what it will do is get you comfortable with a lot of the tools abilities and give you a basic level of knowledge about them. Would I recommend this to anyone interested in getting started with Unity? Absolutely.
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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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