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.

Arrow left icon
Profile Icon Will Goldstone
Arrow right icon
zł59.99 zł177.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (100 Ratings)
eBook Dec 2011 488 pages 1st Edition
eBook
zł59.99 zł177.99
Paperback
zł221.99
Subscription
Free Trial
Arrow left icon
Profile Icon Will Goldstone
Arrow right icon
zł59.99 zł177.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (100 Ratings)
eBook Dec 2011 488 pages 1st Edition
eBook
zł59.99 zł177.99
Paperback
zł221.99
Subscription
Free Trial
eBook
zł59.99 zł177.99
Paperback
zł221.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 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.

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 : 9781849691451
Vendor :
Unity Technologies
Languages :
Concepts :
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 : Dec 20, 2011
Length: 488 pages
Edition : 1st
Language : English
ISBN-13 : 9781849691451
Vendor :
Unity Technologies
Languages :
Concepts :
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 zł20 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 zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 443.98
Unity 3.x Game Development Essentials
zł221.99
Learning C# by Developing Games with Unity 3D Beginner's Guide
zł221.99
Total 443.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

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.