Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo
Unity 3.x Game Development Essentials

Book Description

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.

  • 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

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

    Table of Contents

    1. Unity 3.xGame Development Essentials
      1. Table of Contents
      2. Unity 3.x Game Development Essentials
      3. Credits
      4. Foreword
      5. About the Author
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Getting help with the book and updates
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the book asset bundle
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      9. 1. Enter the Third Dimension
        1. Getting to grips with 3D
          1. Coordinates
          2. Local space versus world space
          3. Vectors
          4. Cameras
            1. Projection mode—3D versus 2D
          5. Polygons, edges, vertices, and meshes
          6. Materials, textures, and shaders
        2. Rigidbody physics
          1. Collision detection
        3. Essential Unity concepts
          1. The Unity way—an example
          2. Assets
          3. Scenes
          4. GameObjects
          5. Components
          6. Scripts
          7. Prefabs
        4. The interface
          1. The Scene view and Hierarchy
            1. Control tools
            2. Flythrough Scene navigation
            3. Control bar
            4. Search box
            5. Create button
          2. The Inspector
          3. The Project window
          4. The Game view
        5. Summary
      10. 2. Prototyping and Scripting Basics
        1. Your first Unity project
        2. A basic prototyping environment
          1. Setting the scene
          2. Adding simple lighting
          3. Another brick in the wall
            1. Building the master brick
            2. And snap!—It's a row
            3. Grouping and duplicating with empty objects
          4. Build it up, knock it down!
            1. Setting the viewpoint
        3. Introducing scripting
          1. A new behaviour script or 'class'
          2. What's inside a new C# behaviour
            1. Basic functions
            2. Variables in C#
          3. What's inside a new Javascript behaviour
            1. Variables in Javascript
            2. Comments
          4. Wall attack
          5. Declaring public variables
            1. Assigning scripts to objects
            2. Moving the camera
            3. Local, private, and public variables
              1. Local variables and receiving input
        4. Understanding Translate
          1. Implementing Translate
        5. Testing the game so far
          1. Making a projectile
            1. Creating the projectile prefab
            2. Creating and applying a material
            3. Adding physics with a Rigidbody
        6. Storing with prefabs
          1. Firing the projectile
        7. Using Instantiate() to spawn objects
          1. Adding a force to the Rigidbody
        8. Summary
      11. 3. Creating the Environment
        1. Designing the game
        2. Using the terrain editor
          1. Terrain menu features
            1. Importing and exporting heightmaps
            2. Setting the resolution
            3. Mass place trees
            4. Flatten Heightmap
            5. Refresh tree and detail prototypes
          2. The terrain toolset
            1. Terrain Script
            2. Raise height
            3. Paint height
            4. Smooth Height
            5. Paint Texture
            6. Place Trees
            7. Paint Details
            8. Terrain Settings
          3. Creating the island—sun, sea, and sand
            1. Step 1—Setting up the terrain
            2. Step 2—Creating the Island outline
            3. Step 3—Volcano!
            4. Step 4—Adding textures
              1. Painting procedure
              2. Sandy areas
              3. Grass & Rock
              4. Volcanoes rock!
            5. Step 5—Tree time
            6. Step 6—The grass is always greener
            7. Step 7—Let there be lights!
              1. Creating sunlight
            8. Step 8—What's that sound?
              1. Sounds—2D versus 3D
              2. Audio file formats
              3. The hills are alive!
              4. Importing the book's asset package
              5. Further audio settings
            9. Step 9—Look, there! Up in the skybox!
            10. Step 10—Open water
            11. Step 11—Going walkabout
            12. Step 12—Final tweaks
        3. Summary
      12. 4. Player Characters and Further Scripting
        1. Working with the Inspector
          1. Tags
          2. Layers
          3. Prefabs and the Inspector
        2. Anatomy of a character
        3. Deconstructing the First Person Controller object
          1. Parent-child issues
          2. First Person Controller object
            1. Object 1: First Person Controller (parent)
              1. Transform
              2. Character Controller
              3. Mouse Look (Script)
              4. Character Motor (Script)
              5. FPSInput Controller (Script)
            2. Object 2: Graphics (child)
              1. Mesh filter
              2. Mesh Renderer
            3. Object 3: Main Camera (child)
              1. Camera
              2. GUILayer and Flare Layer
              3. Mouse Look (Script)
              4. Audio listener
        4. Further scripting
          1. Commands
          2. Variables
            1. Variable data types
            2. Using variables
              1. Public versus private variables
              2. Declaring public and private variables
        5. Full example
          1. Functions
            1. Update()
            2. OnMouseDown()
          2. Writing custom functions
            1. Return type
            2. Arguments
          3. Declaring a custom function
            1. Calling a custom function
          4. If else statements
            1. C#:
          5. Multiple conditions
            1. For loops
        6. Inter-script communication and Dot Syntax
          1. Accessing other objects
          2. Find() and FindWithTag()
          3. SendMessage
          4. GetComponent
            1. Programming for Mobile
            2. Dot Syntax
          5. Comments
            1. Further reading
        7. Scripting for character movement
          1. Deconstructing the script
            1. Full script (Javascript)
          2. Variable declaration
            1. Storing movement information
            2. Moving the character
            3. Checking grounded
            4. @Script commands
        8. Summary
      13. 5. Interactions
        1. External modeling applications
          1. Common settings for models
          2. Meshes
          3. Normals and Tangents
          4. Materials
          5. Animations
          6. Animation Compression
        2. Setting up the outpost model
        3. Adding the outpost
          1. Positioning
          2. Rotation
          3. Adding colliders
          4. Adding the Rigidbody
          5. Adding audio
          6. Disabling automatic animation
        4. Collisions and triggers
        5. Ray casting
          1. The frame miss
          2. Predictive collision detection
        6. Opening the outpost
          1. Approach 1—Collision detection
            1. Creating new assets
            2. Scripting for character collision detection
              1. Working with OnControllerColliderHit
              2. OpenDoor() custom function
                1. Declaring the function
                2. Checking door status
                3. Playing audio
              3. Testing the script
                1. Extending colliders
                2. Playing animation
                3. Reversing the procedure
                4. Code maintainability
                5. Drawbacks of collision detection
          2. Approach 2—Ray casting
            1. Disabling collision detection with comments
            2. Migrating code—writing a DoorManager script
            3. Tidying PlayerCollisions
            4. Casting the ray
            5. Resetting the collider
          3. Approach 3—Trigger collision detection
            1. Creating and scaling the trigger zone
            2. Scripting for trigger collisions
              1. Removing PlayerCollisions
        7. Summary
      14. 6. Collection, Inventory, and HUD
        1. Creating the power cell prefab
          1. Downloading, importing, and placing
          2. Tagging the power cell
          3. Collider scaling and rotation
            1. Enlarging the power cell
            2. Adding a trigger collider
            3. Collider scale
          4. Adding the Rigidbody
          5. Creating the power cell script
            1. Adding rotation
          6. Adding Trigger Collision Detection
          7. Saving as a prefab
        2. Scattering power cells
        3. Writing the Player Inventory
          1. Saving the charge value
            1. Setting the variable start value
            2. Audio feedback
          2. Adding the CellPickup() function
            1. Adding the Inventory to the player
        4. Restricting outpost access
          1. Restricting door access with a cell counter
        5. Displaying the power cell HUD
          1. Import settings for GUI textures
          2. Creating the GUITexture object
          3. Positioning the PowerGUI texture
          4. Scripting for texture swap
          5. Understanding arrays
            1. Adding the HUD array
            2. Assigning textures to the array
            3. Disabling the HUD for game start
            4. Enabling the HUD during runtime
            5. Adding the power generator
          6. Signifying door unlock
            1. Adding the locked light
            2. Switching lights and removing the HUD
        6. Hints for the player
          1. Writing on screen with GUIText
            1. Scripting for GUIText control
            2. Adjusting hints to show progress
            3. Using fonts
        7. Summary
      15. 7. Instantiation and Rigidbodies
        1. Utilizing instantiation
        2. Rigidbodies
          1. Forces
          2. The Rigidbody component
        3. Making the mini-game
          1. Creating the coconut prefab
            1. Creating the textured coconut
            2. Adding physics
            3. Saving as a prefab
          2. Creating the Launcher object
          3. Scripting to throw coconuts
            1. Checking for player input
            2. Playing feedback sound
            3. Instantiating the coconut
            4. Naming instances
            5. Assigning velocity
            6. Adding development safeguards
              1. Ensuring component presence
              2. Safeguarding collisions
                1. Using IgnoreCollision() code
              3. Ignoring collisions with layers
              4. Including the Audio Source component
          4. Final checks
          5. Instantiate restriction and object tidying
            1. Activating coconut throw
              1. Writing the throwing mat trigger script
          6. Adding the coconut shy shack
            1. Import settings
              1. Creating the throwing mat trigger
            2. Removing coconuts
              1. Targets and coconut collisions
            3. Placement
            4. Disabling automatic animation
            5. Adding Rigidbodies to moving parts
            6. Writing the Coconut collision detection script
              1. Establishing variables
              2. Collision detection
              3. Using co-routines to time game elements
              4. Including the Audio Source component
            7. Assigning the script
            8. Creating more targets
          7. Winning the game
            1. Setting up variables
            2. Checking for a win
            3. Script assignment
            4. Incrementing and decrementing target count
              1. Adding to the target count
              2. Subtracting from the target count
          8. Finishing touches
            1. Adding the crosshair
              1. Toggling the crosshair GUI Texture
            2. Informing the player
        4. Summary
      16. 8. Particle Systems
        1. What is a particle system?
          1. Particle Emitter
          2. Particle Animator
          3. Particle Renderer
        2. Creating the task
          1. Assets involved
          2. Adding the log pile
          3. Creating the campfire particle systems
            1. Creating fire
              1. Ellipsoid Particle Emitter settings
              2. Particle Animator settings
              3. Particle Renderer settings
              4. Adding a material
              5. Positioning the FireSystem
              6. Time to Test!
            2. Blowing smoke!
              1. Ellipsoid Particle Emitter settings
              2. Particle Animator settings
              3. Particle Renderer settings
              4. Positioning
            3. Adding audio to the fire
              1. 3D Audio
          4. Lighting the fire
            1. Adding the matches
              1. Writing the Match Collection script
            2. Creating the matches GUI
            3. Collecting the matches
            4. Starting the fire
              1. Using arrays and loops for commands on multiple objects
              2. Signifying Inventory usage
        3. Testing and confirming
          1. So, what's the problem?
            1. Safeguarding with additional conditions
        4. Summary
      17. 9. Designing Menus
        1. Interfaces and menus
          1. Creating the scene
            1. Duplicating the island
              1. Grouping the environment objects
              2. Duplicating the scene
              3. Framing the shot
            2. Preparing textures for GUI usage
            3. Adding the game title
              1. GUITexture formats
              2. Creating the GUITexture object
              3. Positioning
        2. Creating the menu with GUITextures and mouse events
          1. Adding the play button
          2. GUITexture button script
          3. Loading scenes
          4. Assigning public variables
          5. Testing the button
          6. Adding the instructions button
          7. Adding the quit button
          8. Checking scripts with Debug commands
        3. Creating the menu with the Unity GUI class and GUI skins
          1. Disabling game objects
          2. Creating the menu
            1. Creating public variables
            2. The OnGUI() function
            3. Positioning for GUIs
              1. Pixel-specific positioning
            4. Styling GUI buttons with a GUI skin
            5. Using textures for GUI button backgrounds
            6. Choosing font size for GUI buttons
              1. Resolution-independent positioning
            7. Scripting button actions
            8. Adding the Instructions page
              1. Creating menu pages
              2. Formatting the GUI label with the GUI skin asset
              3. A note on optimizing the loading process
        4. Summary
      18. 10. Animation Basics
        1. Game win sequence
          1. Win sequence approach
          2. Triggering the win
          3. Creating the game win messages
            1. Positioning win sequence GUI elements
            2. Grouping GUITextures for optimized instantiation
          4. Animating with linear interpolation (Lerp)
            1. Adjusting animations
            2. Storing the win sequence
          5. Creating the win object
          6. Creating the Fader and using the Animation panel
            1. Scaling for various resolutions
            2. Starting the Fader from invisibility
            3. Animation panel overview
            4. Creating an animation clip
            5. Creating keyframes
            6. Using animation curves
            7. Adding animation events
            8. Creating and animating the Loading GUI
            9. Loading scenes with animation events
            10. Storing and instantiating the Loading GUI
          7. Loading the win sequence
          8. Layering GUITextures
          9. Challenge—fading in the Island scene
        2. Summary
      19. 11. Performance Tweaks and Finishing Touches
        1. Terrain tweaks and player position
          1. Tweaking the terrain
            1. Positioning trees
          2. Hills, troughs, and texture blending
            1. Life's a beach
          3. Keep on the right path
        2. Positioning the player
        3. Optimizing performance
          1. Camera Clip Planes and Fog
          2. Lightmapping
            1. Lighting and baking the island
            2. Preparing for lightmapping
              1. The outpost and generator
                1. Lighting inside the outpost
                2. Lighting a mesh with a Self Illuminated shader
                3. Lighting inside with Baked-Only Point Lights
              2. The coconut shy
              3. The campfire
            3. Baking the lightmap
              1. Lightmapping overview
              2. Ambient lighting
              3. Including lights
              4. Excluding from the bake
              5. Baking the scene
            4. Restoring dynamic objects
        4. Finishing touches
          1. Volcano!
            1. Positioning the particle system
              1. Required assets
            2. Making the smoke material
            3. Particle system settings
              1. Ellipsoid Particle Emitter settings
              2. Particle Animator settings
            4. Adding audio to the volcano
            5. Volcano testing
          2. Coconut trails
            1. Editing the Prefab
            2. Trail Renderer component
            3. Updating the prefab
          3. Summary
      20. 12. Building and Sharing
        1. Build options
          1. Web Player
            1. Web Player Streamed
          2. PC or Mac standalone
          3. OSX Dashboard Widget
        2. Build Settings
        3. Player Settings
          1. Cross-Platform Settings
          2. Per-Platform Settings
            1. Resolution and Presentation
              1. Web Player Settings
              2. Standalone Settings
            2. Icon
              1. Standalone
            3. Splash Image
              1. Standalone
            4. Other Settings
              1. Web Player
              2. Standalone
        4. Quality Settings
        5. Player Input settings
        6. Building the game
          1. Adapting for web build
            1. Quit button platform automation
            2. Preparing for streaming
              1. Displaying streamed loading progress
              2. Styling the loading info box
          2. First Build
            1. Building the Standalone
            2. Free versus Pro
          3. Building for the Web
            1. Embedding web player builds in your own site
              1. The <head>—web JavaScript
              2. Making the <head> code portable
              3. Object embedding from the <BODY>
              4. Styling your Unity embed with CSS
        7. Sharing your work
          1. Sharing on Kongregate.com
        8. Summary
      21. 13. Testing and Further Study
        1. Learn by doing
        2. Testing and finalizing
          1. Public testing
            1. Frame rate feedback
            2. Optimizing performance
        3. Approaches to learning
          1. Cover as many bases as possible
          2. Don't reinvent the wheel
          3. If you don't know, just ask!
        4. Summary
      22. Index