Unity 4.x Cookbook

Unity 4.x Cookbook
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • A wide range of topics are covered, ranging in complexity, offering something for every Unity 4 game developer
  • Every recipe provides step-by-step instructions, followed by an explanation of how it all works, and alternative approaches or refinements
  • Book developed with the latest version of Unity (4.x)

Book Details

Language : English
Paperback : 386 pages [ 235mm x 191mm ]
Release Date : June 2013
ISBN : 1849690421
ISBN 13 : 9781849690423
Author(s) : Matt Smith, Chico Queiroz
Topics and Technologies : All Books, Game Development, Unity, Cookbooks

Table of Contents

Chapter 1: Getting Started with Unity 4.x
Chapter 2: Using Cameras
Chapter 3: Creating Maps and Materials
Chapter 4: Creating GUIs
Chapter 5: Controlling Animations
Chapter 6: Playing and Manipulating Sounds
Chapter 7: Working with External Resource Files and Devices
Chapter 8: Working with External Text Files and XML Data
Chapter 9: Managing Object States and Controlling Their Movements
Chapter 10: Improving Games with Extra Features and Optimization
Chapter 11: Taking Advantage of Unity Pro
  • Chapter 1: Getting Started with Unity 4.x
    • Introduction
    • Installing Unity 4.x
    • Setting your preferences
    • Understanding and optimizing the User Interface
    • Saving assets created in Unity as Prefabs
    • Discovering Unity's content
    • Importing your own content
    • Importing Unity packages into your project
    • Importing custom packages into your project
    • Exporting custom packages from your project
    • Adding custom packages to Unity's quick list
    • Using the Project browser
    • Chapter 2: Using Cameras
      • Introduction
      • Creating a picture-in-picture effect
      • Switching between multiple cameras
      • Customizing the lens flare effect
      • Making textures from screen content
      • Zooming a telescopic camera
      • Making an inspect camera
      • Creating particle effects using Shuriken
      • Displaying a mini-map
      • Chapter 3: Creating Maps and Materials
        • Introduction
        • Creating a reflective material
        • Creating a self-illuminated material
        • Creating specular texture maps
        • Creating transparency texture maps
        • Using cookie textures to simulate a cloudy outdoor
        • Creating a color selection dialog
        • Combining textures in real time through the GUI
        • Highlighting materials at mouse over
        • Animating textures by looping through array of materials (for example, simulated video)
        • Disabling culling for a material
        • Chapter 4: Creating GUIs
          • Introduction
          • Displaying a digital clock
          • Displaying an analogue clock
          • Displaying a compass to show player direction
          • Displaying a radar to indicate relative locations of objects
          • Displaying images for corresponding integers
          • Displaying images for corresponding floats and ranges
          • Displaying a digital countdown timer
          • Displaying a countdown timer graphically (5, 4, 3, 2, 1 – blast off)
          • Displaying a countdown timer graphically as a pie-chart style clock
          • Creating a message that fades away
          • Displaying inventory texts for single object pickups
          • Displaying inventory icons for single object pickups
          • Managing inventories with a general purpose PickUp class
          • Controlling the scrollbar with the mouse wheel
          • Implementing custom mouse cursor icons
          • Chapter 5: Controlling Animations
            • Introduction
            • Configuring a character's Avatar and Idle animation
            • Moving your character with Root Motion and Blend Trees
            • Mixing animations with Layers and Masks
            • Overriding Root Motion via script
            • Adding rigid props to animated characters
            • Making an animated character throw an object
            • Applying ragdoll physics to a character
            • Rotating the character's torso to aim
            • Chapter 6: Playing and Manipulating Sounds
              • Introduction
              • Matching audio pitch to animation speed
              • Adding customizable volume controls
              • Simulating a tunnel environment with Reverb Zones
              • Preventing the AudioClip from restarting if already playing
              • Waiting for audio to finish before auto-destructing an object
              • Making a dynamic soundtrack
              • Chapter 7: Working with External Resource Files and Devices
                • Introduction
                • Loading external resource files – by Unity Default Resources
                • Loading external resource files – by manually storing files in Unity's Resources folder
                • Loading external resource files – by downloading files from the Internet
                • Saving and loading player data – using static properties
                • Saving and loading player data – using PlayerPrefs
                • Saving screenshots from the game
                • Control characters in Unity with the Microsoft Kinect using the Zigfu samples
                • Animating your own characters with the Microsoft Kinect controller
                • Homemade mocap by storing movements from the Microsoft Kinect controller
                • Setting up a leaderboard using PHP/MySQL
                • Chapter 8: Working with External Text Files and XML Data
                  • Introduction
                  • Loading external text files using the TextAsset public variable
                  • Loading external text files using C# file streams
                  • Saving external text files with C# file streams
                  • Loading and parsing external XML files
                  • Creating XML text data manually using XMLWriter
                  • Creating XML text data automatically through serialization
                  • Creating XML text files – saving XML directly to text files with XMLDocument.Save()
                  • Chapter 9: Managing Object States and Controlling Their Movements
                    • Introduction
                    • Controlling cube movement through player controls
                    • Controlling object look-at behavior
                    • Controlling object-to-object movements (seek, flee, follow at a distance)
                    • Controlling object group movement through flocking
                    • Firing objects by instantiation with forward velocity
                    • Finding a random spawn point
                    • Finding the nearest spawn point
                    • Following waypoints in a sequence
                    • Managing object behavior with states
                    • Managing complex object behavior with the state pattern
                    • Chapter 10: Improving Games with Extra Features and Optimization
                      • Introduction
                      • Pausing the game
                      • Implementing slow motion
                      • Implementing 3D stereography with polarized projection
                      • Preventing your game from running on unknown servers
                      • Identifying performance "bottlenecks" with code profiling
                      • Reducing the number of objects by destroying objects at a "death" time
                      • Reducing the number of enabled objects by disabling objects whenever possible
                      • Improving efficiency with delegates and events (and avoiding SendMessage!)
                      • Executing methods regularly but independent of frame rate with coroutines
                      • Spreading long computations over several frames with coroutines
                      • Caching, rather than component lookups and "reflection" over objects
                      • Chapter 11: Taking Advantage of Unity Pro
                        • Introduction
                        • Dynamically focusing objects with Depth of Field
                        • Creating a rearview mirror
                        • Playing videos inside a scene
                        • Simulating underwater ambience with audio filters
                        • Loading and playing external movie files

                        Matt Smith

                        Matt Smith is senior lecturer in computing at the Institute of Technology Blanchardstown, Dublin, Ireland (www.itb.ie). In 1980 (you do the math) Matt started computer programming (on a ZX80) and has been programming ever since. In 1985, Matt wrote the lyrics, and was a member of the band that played (and sang, sorry about that by the way) the music on the B-side of the audio cassette carrying the computer game Confuzion (wikipedia.org/wiki/Confuzion). Matt holds a bachelor's degree in Business Computing (Huddersfield University, UK), and as that was a bit boring, he went on to get a masters in Artificial Intelligence (Aberdeen University, Scotland), and a PhD in Computational Musicology (Open University, UK). Having run out of money after 10 years as a full-time student, he began his career as a lecturer and academic. He has been lecturing and researching on programming, artificial intelligence, web development, and interactive multimedia for almost 20 years, holding full-time positions at Winchester University and London's Middlesex University, before moving to his present post in Ireland in 2002. In recent years, Matt has replaced Flash-based 2D multimedia with Unity-based 3D game development and interactive virtual environments subjects for his computing and digital media undergraduates. To keep himself fit, Matt took up the Korean martial art of Taekwon-Do (he developed and runs his club's website at www.maynoothtkd.com), and a group of his BSc students are now developing a Unity-based Taekwon-Do interactive "tutor" with Microsoft Kinect cameras. Some of his previous Irish-French student team games can be found and played at www.saintgermes.com (thanks for continuing to host these, Guillem!). Matt was one of the two technical experts for a recent multimedia European project for language and cultural student work mobility (vocalproject.eu). Matt is currently struggling to learn Korean (for his Taekwon-Do), and Irish (since his daughter Charlotte attends an Irish-speaking school and he doesn't believe her translations of her teacher's report cards ...). In 2012, he started taking classical piano lessons again (after a 20-year gap), with a view to sitting exams starting May, 2013. Matt's previous authoring includes contributions to Serious Games and Edutainment Applications, Springer (2011), Musical Imagery, Routledge (2001). He was also lead editor for Music Education: An Artificial Intelligence Approach, Springer (1994), and a technical reviewer for Internet and World Wide Web: How to Program (3rd Edition) by Deitel, Deitel & Goldberg, Prentice Hall (2003).

                        Chico Queiroz

                        Chico Queiroz is a multimedia designer from Rio de Janeiro, Brazil. Chico initiated his career back in 2000, soon after graduating in Communications/Advertising (PUC-Rio), working with advergames and webgames using Flash and Director at LocZ Multimedia. Here he contributed to the design and development of games for clients, such as Volkswagen and Parmalat, along with some independent titles. Chico has a Master's Degree in Digital Game Design (University for the Creative Arts, UK). His final project was exhibited at events and festivals, such as London Serious Games Showcase and FILE. Chico has also published articles for academic conferences and websites, such as gameology.org, gamasutra.com, and gamecareerguide.com. He curated and organized an exhibition, held at SBGames 2009, which explored connections between video games and art. SBGames is the annual symposium of the Special Commission of Games and Digital Entertainment of the Computing Brazilian Society. Chico currently works as a Digital Designer at the Computer Graphics Technology Group (TecGraf), within the Pontifical Catholic University of Rio de Janeiro (PUC-Rio), where he, among other responsibilities, uses Unity to develop interactive presentations and concept prototypes for interactive visualization software. He also works as a lecturer at PUC-Rio, teaching undergraduate Design students 3D modeling and Technology/CG for Games, in which Unity is used as the engine for the students' projects.
                        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.


                        - 4 submitted: last submission 08 Apr 2014

                        Errata type: Typo | Page number: 21

                        Under the How to do it... section, in step 2, it should read "the Select Dependencies option" instead of "the Select Decencies option"


                        Errata type: Technical | Page number: 52

                        Window | Particle Effects does not exist anymore. Instead open the Particle  
                        editor using the "OpenEditor" button in the Particle System Component part of  
                        the Inspector.

                        Errata type: Typo | Page number: 55

                        The sixth line of code on page 55 has two semicolons (;;). The correct sixth line of code is as follows (with a single semicolon):


                        Errata type: Technical | Page number: 274

                        On page 274, the step number 6 has some changes. We have to drag Cube-player over the public variable named playerGO not over playerTransform.

                        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 4.x Cookbook +    IBM WebSphere Application Server 8.0 Administration Guide =
                        50% Off
                        the second eBook
                        Price for both: $45.60

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

                        What you will learn from this book

                        • Enhance your character`s animation in real time using Unity`s new Mecanim system
                        • Measure and control time, including pausing the game, displaying clocks and countdown timers, and even implementing “bullet time” effects
                        • Work with cameras, images, and the Shuriken practical system, to create mini-maps, control zooming, and depth of field, and switch between cameras
                        • Define materials for reflections, transparency, specular and self-illumination of materials, and cloudy outdoor effects
                        • Use artificial intelligence techniques to make non-player character objects seek, follow, flee each other, or follow a waypoint sequence, and even flock together like a herd of animals
                        • Make your game communicate with Microsoft Kinect cameras, for control of game characters, and even to record your own motion capture
                        • Improve GUIS with real-time radars, custom mouse cursors, analogue and digital clocks, color section dialogs, mouse over material highlighting, graphical power-bars, and a flexible inventory class
                        • Save and load text, XML, or media assets from local or remote sources, and communicate with websites and their databases to create online scoreboards

                        In Detail

                        Covering the latest version (Unity 4) of this established game engine, the Unity 4.x Cookbook explores a wide range of 3D, animation, multimedia, and scripting game features.

                        The power of Unity 4 is demonstrated through the 10 chapters covering many of this game engine’s features.

                        "Unity 4.x Cookbook" helps you learn how to make the most of the powerful but easy-to-use Unity 4 game engine.

                        Every Unity game developer is different. Some come from a multimedia background, some are new to game development, and some are transferring from other engines. Whatever your background, with the breadth and depth of topics covered you should find new features and techniques to enhance your next game.

                        This book offers detailed, easy-to-follow, step-by-step recipes helping you master a wide range of Unity game features.

                        Chapters are provided focusing on the basics; audio, cameras, images, materials and animations, GUIs, external resources and devices, directional and artificial intelligence character control, and performance optimization.

                        "Unity 4.x Cookbook" provides a collection of ideas and resources that should offer new and useful techniques for every Unity game developer to enhance their next game.



                        Who this book is for

                        From beginners to advanced users, from artists to coders, this book is for you and everyone in your team!

                        This book is for anyone who wants to explore a wide range of Unity scripting and multimedia features and to find ready to use solutions to many game features. Programmers can explore multimedia features, and multimedia developers can try their hand at scripting.

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