Unity 3.x Game Development Essentials


Unity 3.x Game Development Essentials
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$25.49
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • 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
  • Download a glossary of technical terms from the book
  • Download color images from the book

Book Details

Language : English
Paperback : 488 pages [ 235mm x 191mm ]
Release Date : December 2011
ISBN : 1849691444
ISBN 13 : 9781849691444
Author(s) : Will Goldstone
Topics and Technologies : All Books, Game Development, Unity, Games

Table of Contents

Preface
Chapter 1: Enter the Third Dimension
Chapter 2: Prototyping and Scripting Basics
Chapter 3: Creating the Environment
Chapter 4: Player Characters and Further Scripting
Chapter 5: Interactions
Chapter 6: Collection, Inventory, and HUD
Chapter 7: Instantiation and Rigidbodies
Chapter 8: Particle Systems
Chapter 9: Designing Menus
Chapter 10: Animation Basics
Chapter 11: Performance Tweaks and Finishing Touches
Chapter 12: Building and Sharing
Chapter 13: Testing and Further Study
Glossary
Index
  • Chapter 1: Enter the Third Dimension
    • Getting to grips with 3D
      • Coordinates
      • Local space versus world space
      • Vectors
      • Cameras
        • Projection mode—3D versus 2D
      • Polygons, edges, vertices, and meshes
      • Materials, textures, and shaders
    • Rigidbody physics
      • Collision detection
    • Essential Unity concepts
      • The Unity way—an example
      • Assets
      • Scenes
      • GameObjects
      • Components
      • Scripts
      • Prefabs
    • The interface
      • The Scene view and Hierarchy
        • Control tools
        • Flythrough Scene navigation
        • Control bar
        • Search box
        • Create button
      • The Inspector
      • The Project window
      • The Game view
    • Summary
    • Chapter 2: Prototyping and Scripting Basics
      • Your first Unity project
      • A basic prototyping environment
        • Setting the scene
        • Adding simple lighting
        • Another brick in the wall
          • Building the master brick
          • And snap!—It's a row
          • Grouping and duplicating with empty objects
        • Build it up, knock it down!
          • Setting the viewpoint
      • Introducing scripting
        • A new behaviour script or 'class'
        • What's inside a new C# behaviour
          • Basic functions
          • Variables in C#
        • What's inside a new Javascript behaviour
          • Variables in Javascript
          • Comments
        • Wall attack
        • Declaring public variables
          • Assigning scripts to objects
          • Moving the camera
          • Local, private, and public variables
      • Understanding Translate
        • Implementing Translate
      • Testing the game so far
        • Making a projectile
          • Creating the projectile prefab
          • Creating and applying a material
          • Adding physics with a Rigidbody
      • Storing with prefabs
        • Firing the projectile
      • Using Instantiate() to spawn objects
        • Adding a force to the Rigidbody
      • Summary
      • Chapter 3: Creating the Environment
        • Designing the game
        • Using the terrain editor
          • Terrain menu features
            • Importing and exporting heightmaps
            • Setting the resolution
            • Mass place trees
            • Flatten Heightmap
            • Refresh tree and detail prototypes
          • The terrain toolset
            • Terrain Script
            • Raise height
            • Paint height
            • Smooth Height
            • Paint Texture
            • Place Trees
            • Paint Details
            • Terrain Settings
          • Creating the island—sun, sea, and sand
            • Step 1—Setting up the terrain
            • Step 2—Creating the Island outline
            • Step 3—Volcano!
            • Step 4—Adding textures
            • Step 5—Tree time
            • Step 6—The grass is always greener
            • Step 7—Let there be lights!
            • Step 8—What's that sound?
            • Step 9—Look, there! Up in the skybox!
            • Step 10—Open water
            • Step 11—Going walkabout
            • Step 12—Final tweaks
        • Summary
        • Chapter 4: Player Characters and Further Scripting
          • Working with the Inspector
            • Tags
            • Layers
            • Prefabs and the Inspector
          • Anatomy of a character
          • Deconstructing the First Person Controller object
            • Parent-child issues
            • First Person Controller object
              • Object 1: First Person Controller (parent)
              • Object 2: Graphics (child)
              • Object 3: Main Camera (child)
          • Further scripting
            • Commands
            • Variables
              • Variable data types
              • Using variables
          • Full example
            • Functions
              • Update()
              • OnMouseDown()
            • Writing custom functions
              • Return type
              • Arguments
            • Declaring a custom function
              • Calling a custom function
            • If else statements
            • Multiple conditions
              • For loops
          • Inter-script communication and Dot Syntax
            • Accessing other objects
            • Find() and FindWithTag()
            • SendMessage
            • GetComponent
            • Comments
              • Further reading
          • Scripting for character movement
            • Deconstructing the script
              • Full script (Javascript)
            • Variable declaration
              • Storing movement information
              • Moving the character
              • Checking grounded
              • @Script commands
          • Summary
          • Chapter 5: Interactions
            • External modeling applications
              • Common settings for models
              • Meshes
              • Normals and Tangents
              • Materials
              • Animations
              • Animation Compression
            • Setting up the outpost model
            • Adding the outpost
              • Positioning
              • Rotation
              • Adding colliders
              • Adding the Rigidbody
              • Adding audio
              • Disabling automatic animation
            • Collisions and triggers
            • Ray casting
              • The frame miss
              • Predictive collision detection
          • Opening the outpost
            • Approach 1—Collision detection
              • Creating new assets
              • Scripting for character collision detection
            • Approach 2—Ray casting
              • Disabling collision detection with comments
              • Migrating code—writing a DoorManager script
              • Tidying PlayerCollisions
              • Casting the ray
              • Resetting the collider
            • Approach 3—Trigger collision detection
              • Creating and scaling the trigger zone
              • Scripting for trigger collisions
          • Summary
            • Chapter 6: Collection, Inventory, and HUD
              • Creating the power cell prefab
                • Downloading, importing, and placing
                • Tagging the power cell
                • Collider scaling and rotation
                  • Enlarging the power cell
                  • Adding a trigger collider
                  • Collider scale
                • Adding the Rigidbody
                • Creating the power cell script
                  • Adding rotation
                • Adding Trigger Collision Detection
                • Saving as a prefab
              • Scattering power cells
              • Writing the Player Inventory
                • Saving the charge value
                  • Setting the variable start value
                  • Audio feedback
                • Adding the CellPickup() function
                  • Adding the Inventory to the player
              • Restricting outpost access
                • Restricting door access with a cell counter
              • Displaying the power cell HUD
                • Import settings for GUI textures
                • Creating the GUITexture object
                • Positioning the PowerGUI texture
                • Scripting for texture swap
                • Understanding arrays
                  • Adding the HUD array
                  • Assigning textures to the array
                  • Disabling the HUD for game start
                  • Enabling the HUD during runtime
                  • Adding the power generator
                • Signifying door unlock
                  • Adding the locked light
                  • Switching lights and removing the HUD
              • Hints for the player
                • Writing on screen with GUIText
                  • Scripting for GUIText control
                  • Adjusting hints to show progress
                  • Using fonts
              • Summary
              • Chapter 7: Instantiation and Rigidbodies
                • Utilizing instantiation
                • Rigidbodies
                  • Forces
                  • The Rigidbody component
                • Making the mini-game
                  • Creating the coconut prefab
                    • Creating the textured coconut
                    • Adding physics
                    • Saving as a prefab
                  • Creating the Launcher object
                  • Scripting to throw coconuts
                    • Checking for player input
                    • Playing feedback sound
                    • Instantiating the coconut
                    • Naming instances
                    • Assigning velocity
                    • Adding development safeguards
                  • Final checks
                  • Instantiate restriction and object tidying
                    • Activating coconut throw
                  • Adding the coconut shy shack
                    • Import settings
                    • Removing coconuts
                    • Placement
                    • Disabling automatic animation
                    • Adding Rigidbodies to moving parts
                    • Writing the Coconut collision detection script
                    • Assigning the script
                    • Creating more targets
                  • Winning the game
                    • Setting up variables
                    • Checking for a win
                    • Script assignment
                    • Incrementing and decrementing target count
                  • Finishing touches
                    • Adding the crosshair
                    • Informing the player
                • Summary
                • Chapter 8: Particle Systems
                  • What is a particle system?
                    • Particle Emitter
                    • Particle Animator
                    • Particle Renderer
                  • Creating the task
                    • Assets involved
                    • Adding the log pile
                    • Creating the campfire particle systems
                      • Creating fire
                      • Blowing smoke!
                      • Adding audio to the fire
                    • Lighting the fire
                      • Adding the matches
                      • Creating the matches GUI
                      • Collecting the matches
                      • Starting the fire
                  • Testing and confirming
                    • So, what's the problem?
                      • Safeguarding with additional conditions
                  • Summary
                  • Chapter 9: Designing Menus
                    • Interfaces and menus
                      • Creating the scene
                        • Duplicating the island
                        • Preparing textures for GUI usage
                        • Adding the game title
                    • Creating the menu with GUITextures and mouse events
                      • Adding the play button
                      • GUITexture button script
                      • Loading scenes
                      • Assigning public variables
                      • Testing the button
                      • Adding the instructions button
                      • Adding the quit button
                      • Checking scripts with Debug commands
                    • Creating the menu with the Unity GUI class and GUI skins
                      • Disabling game objects
                      • Creating the menu
                        • Creating public variables
                        • The OnGUI() function
                        • Positioning for GUIs
                        • Styling GUI buttons with a GUI skin
                        • Using textures for GUI button backgrounds
                        • Choosing font size for GUI buttons
                        • Scripting button actions
                        • Adding the Instructions page
                    • Summary
                    • Chapter 10: Animation Basics
                      • Game win sequence
                        • Win sequence approach
                        • Triggering the win
                        • Creating the game win messages
                          • Positioning win sequence GUI elements
                          • Grouping GUITextures for optimized instantiation
                        • Animating with linear interpolation (Lerp)
                          • Adjusting animations
                          • Storing the win sequence
                        • Creating the win object
                        • Creating the Fader and using the Animation panel
                          • Scaling for various resolutions
                          • Starting the Fader from invisibility
                          • Animation panel overview
                          • Creating an animation clip
                          • Creating keyframes
                          • Using animation curves
                          • Adding animation events
                          • Creating and animating the Loading GUI
                          • Loading scenes with animation events
                          • Storing and instantiating the Loading GUI
                        • Loading the win sequence
                        • Layering GUITextures
                        • Challenge—fading in the Island scene
                      • Summary
                      • Chapter 11: Performance Tweaks and Finishing Touches
                        • Terrain tweaks and player position
                          • Tweaking the terrain
                            • Positioning trees
                          • Hills, troughs, and texture blending
                            • Life's a beach
                          • Keep on the right path
                        • Positioning the player
                        • Optimizing performance
                          • Camera Clip Planes and Fog
                          • Lightmapping
                            • Lighting and baking the island
                            • Preparing for lightmapping
                            • Baking the lightmap
                            • Restoring dynamic objects
                        • Finishing touches
                          • Volcano!
                            • Positioning the particle system
                            • Making the smoke material
                            • Particle system settings
                            • Adding audio to the volcano
                            • Volcano testing
                          • Coconut trails
                            • Editing the Prefab
                            • Trail Renderer component
                            • Updating the prefab
                          • Summary
                        • Chapter 12: Building and Sharing
                          • Build options
                            • Web Player
                              • Web Player Streamed
                            • PC or Mac standalone
                            • OSX Dashboard Widget
                          • Build Settings
                          • Player Settings
                            • Cross-Platform Settings
                            • Per-Platform Settings
                        • Quality Settings
                        • Player Input settings
                        • Building the game
                          • Adapting for web build
                            • Quit button platform automation
                            • Preparing for streaming
                          • First Build
                            • Building the Standalone
                            • Free versus Pro
                          • Building for the Web
                            • Embedding web player builds in your own site
                        • Sharing your work
                          • Sharing on Kongregate.com
                        • Summary
                          • Chapter 13: Testing and Further Study
                            • Learn by doing
                            • Testing and finalizing
                              • Public testing
                                • Frame rate feedback
                                • Optimizing performance
                            • Approaches to learning
                              • Cover as many bases as possible
                              • Don't reinvent the wheel
                              • If you don't know, just ask!
                            • Summary

                            Will Goldstone

                            Will Goldstone is a longstanding member of the Unity community and works for Unity Technologies as a Technical Support Associate, handling educational content and developer support. With an MA in Creative Education, and many years experience as a lecturer in higher education, Will wrote the first ever Unity book, the original Unity Game Development Essentials, and also created the first ever video tutorials for the package. Through his sites http://www.unity3dstudent.com and http://learnunity3d.com Will helps to introduce new users to the growing community of developers discovering Unity every day.
                            Sorry, we don't have any reviews for this title yet.

                            Code Downloads

                            Download the code and support files for this book.


                            Submit Errata

                            Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                            Errata

                            - 11 submitted: last submission 28 Oct 2013

                            Unity 3.x Game Development Essentials by Will Goldstone

                            The Author also maintains an updated repository of Errata and Code at Unity 3.x Game Development Essentials by Will Goldstone

                             

                            Errata type: Typo | Page number: 258

                            Javascript variable declaration, spaces mistakenly added by publisher Lines within the Javascript chunk in the middle of the page, that say:

                            var hit Sound : AudioClip;
                            var reset Sound : AudioClip;
                            var reset Time : AudioClip;
                            

                            Spaces have been placed into the names, remove them so it reads:

                            var hitSound : AudioClip;
                            var resetSound : AudioClip;
                            var resetTime : AudioClip;
                            

                             

                             

                            Errata type: Technical | Page number: 327

                            Javascript variable declaration. The second line:

                            var GUISkin : GUISkin;

                            Should read:

                            var menuSkin : GUISkin;

                             

                             

                            Errata type: Technical/Typo | Page number: 169

                            Javascript Typo, Lower case “s” in the function name shutDoor.

                            function shutDoor(door : GameObject){

                            Should read:

                            function ShutDoor(door : GameObject){

                             

                             

                            Errata type: Technical/Typo | Page number: 264

                            Javascript code missing a space

                            @scriptRequireComponent(AudioSource)
                            

                            should read -

                            @script RequireComponent(AudioSource)

                             

                             

                            Errata type: Technical/Typo | Page number: 267

                            JavaScript code missing ‘var’

                            winCell : GameObject = transform.Find(“powerCell”).gameObject;
                            

                            Should read:

                            var winCell : GameObject = transform.Find(“powerCell”).gameObject;
                            

                            (as shown in the complete script on the following page).

                             

                             

                            Errata type: Technical | Page number: 300 - 301

                            Javascript code error
                            On this page, we use Javascript code to grab both Particle Emitters – the fire and the smoke – and then set their emit value to true.
                            The book states that you should use this line:

                            var FireEmitters : ParticleEmitter[];
                            

                            followed by this for loop to go through the array and set each emitter found to true:

                            for(var emitter : ParticleEmitter in fireEmitters){
                            emitter.emit = true;
                            }
                            

                            Whilst this approach works in C#, it was not sufficiently tested in Javascript. Apologies for this mistake. The reason this does not work is that in Javascript, the GetComponentsInChildren command returns an array of Components instead of specifically ParticleEmitter components, so they must be converted during the array.
                            Delete the aforementioned code, and place in the following:

                            var fireEmitterComponents : Component[] =     campfire.GetComponentsInChildren(ParticleEmitter);
                            
                            var fireEmitter : ParticleEmitter;
                            
                            for (var i=0; i< fireEmitterComponents.Length; i++) {
                            fireEmitter = fireEmitterComponents[i] as ParticleEmitter;
                            fireEmitter.emit=true;
                            }
                            

                            Here we begin by establishing an array of type Component[]. We then set this using the equals symbol to Particle Emitters found in the campfire gameobject’s children as before.
                            We then make a singular variable called FireEmitter, of type ParticleEmitter. This is then used in the for loop to represent the current emitter being modified. We then make a for loop that begins by creating a variable called ‘i’, set to 0. This variable represents the particular entry in the array, so wherever you see ‘i’ mentioned, this means the current entry in the array that is being addressed. The loop runs for as many entries as there are in the fireEmitterComponents array – hence the use of ‘.Length’.
                            For each entry in the array, we use our temporary fireEmitter variable created above the for loop, and set it equal to the current entry in the fireEmitterComponents array, setting its type to ParticleEmitter by using ‘as ParticleEmitter’. We then set this emitter’s emit value to true as done originally in the book.

                             

                             

                            Errata type: Technical/Typo | Page number: 354

                            Javascript code typo

                            var winObject : GameObject;
                            

                            Should read:

                            var winObj : GameObject;

                             

                             

                            Errata type: Technical | Page number: 182

                            Missing 'Player' Tag on First Person Controller Prefab Due to a mistake in the Prefab provided by Unity Technologies – the First Person Controller prefab that you import at the start of the book does not have the tag 'Player' as its counterpart Third Person Controller does. The TriggerZone script relies on this tag being on the First Person Controller prefab (and therefore on the game object in the scene), so simply select it within the Standard Assets | Character Controllers folder of the Project panel, and choose Player from the Tag drop-down menu at the top of the Inspector panel.

                             

                            Errata type: Typo | Page number: 126

                            Here the variable enemyShip is assigned the ship_object game object thanks to the use of Find(), by addressing its hierarchical name.

                            should be

                            Here the variable enemyShip is assigned the ship_model game object thanks to the use of Find(), by addressing its hierarchical name.

                            Errata type: Others | Page number: 126 | Errata date: 8-11-2012

                            The text repeatedly says we are looking for an object called "ship_object", but the code actually looks for an object called "ship_model".

                             

                            Sample chapters

                            You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                            Frequently bought together

                            Unity 3.x Game Development Essentials +    VMware View 5 Desktop Virtualization Solutions =
                            50% Off
                            the second eBook
                            Price for both: £27.35

                            Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                            What you will learn from this book

                            • 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.

                             

                            In Detail

                            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!

                            Approach

                            This book follows an informal, demystifying approach to the world of game development with the Unity game engine. With no prior knowledge of game development or 3D required, you will learn from scratch, taking each concept at a time working up to a full 3D mini-game. You'll learn scripting with C# or JavaScript and master the Unity development environment with easy-to-follow stepwise tasks.

                            Who this book is 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.

                            Code Download and Errata
                            Packt Anytime, Anywhere
                            Register Books
                            Print Upgrades
                            eBook Downloads
                            Video Support
                            Contact Us
                            Awards Voting Nominations Previous Winners
                            Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                            Resources
                            Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software