You are previewing Unity Game Development Essentials.
O'Reilly logo
Unity Game Development Essentials

Book Description

Build fully functional, professional 3D games with realistic environments, sound, dynamic effects, and more!

  • Kick start 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 and optimize your game to perfection with essential tips-and-tricks

  • Written in clear, plain English, this book is packed with working examples and innovative ideas

  • This book is based on Unity version 2.5 and uses JavaScript for scripting

In Detail

Game engines are central to the video games we know and love. From the artwork to the mathematics that underpin the frames onscreen, the engine calls the shots. Aside from offering one of the leading 3D game engines, Unity also provides a superlative development tool - a tool that can produce professional standard games for Mac, PC, and the Unity Web Player.

This book is a complete exercise in game development covering environments, physics, sound, particles, and much more, to get you up and working with Unity quickly.

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. From creating 3D worlds to scripting and creating simple game elements you will learn everything you’ll need to get started with game development for the PC, Mac, and Web.

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. 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 Game Development Essentials
    1. Unity Game Development Essentials
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. Preface
      1. What this book covers
          1. Chapter 1 Welcome to the Third Dimension
          2. Chapter 2 Environments
          3. Chapter 3 Player Characters
          4. Chapter 4 Interactions
          5. Chapter 5 Prefabs, Collection, and HUD
          6. Chapter 6 Instantiation and Rigidbodies
          7. Chapter 7 Particle Systems
          8. Chapter 8 Menu Design
          9. Chapter 9 Finishing Touches
          10. Chapter 10 Building and sharing
          11. Chapter 11 Testing and further study
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the necessary assets for the book
        2. Errata
        3. Piracy
        4. Questions
    6. 1. Welcome to the Third Dimension
      1. Getting to grips with 3D
        1. Coordinates
        2. Local space versus World space
        3. Vectors
        4. Cameras
        5. Polygons, edges, vertices, and meshes
        6. Materials, textures, and shaders
        7. Rigid Body physics
        8. Collision detection
      2. Essential Unity concepts
        1. The Unity way
          1. Assets
          2. Scenes
          3. Game Objects
          4. Components
          5. Scripts
          6. Prefabs
      3. The interface
        1. The Scene window and Hierarchy
        2. The Inspector
        3. The Project window
        4. The Game window
      4. Summary
    7. 2. Environments
        1. External modellers
        2. Resources
      1. Your first Unity project
      2. Using the terrain editor
        1. Terrain menu features
          1. Importing and exporting heightmaps
          2. Set Heightmap resolution
          3. Creating the lightmap
          4. Mass Place Trees
          5. Flatten Heightmap
          6. 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. Sun, Sea, Sand creating the island
            1. Step 1— Terrain setup
            2. Step 2— 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 —Grassed up
            7. Step 7— Let there be lights!
              1. Creating sunlight
            8. Step 8— What's that sound?
              1. Stereo versus Mono
              2. Formats
              3. The hills are alive!
              4. Importing your first package
              5. Further audio settings
            9. Step 9— Look to the skybox!
            10. Step 10— Open water
            11. Step 11— Island walkabout
            12. Step 12— Sun alignment and final tweaks
        4. Take Me Home! Introducing models
          1. Importing the model package
          2. Common settings for models
            1. Meshes
            2. Materials
            3. Animations
          3. Setting up the outpost model
      3. Summary
    8. 3. Player Characters
      1. Working with the Inspector
        1. Tags
        2. Layers
        3. Prefabs and the Inspector
      2. Deconstructing the First Person Controller object
        1. Parent-child issues
        2. First Person Controller objects
          1. Object 1: First Person Controller (parent)
            1. Transform
            2. FPSWalker (Script)
            3. Character Controller
            4. Mouse Look (Script)
          2. Object 2: Graphics
            1. Mesh filter
            2. Mesh renderer
          3. Object 3: Main Camera
            1. Camera
            2. GUILayer and Flare Layer
            3. Mouse Look (Script)
            4. Audio listener
      3. Scripting basics
          1. Commands
          2. Variables
            1. Variable data types
            2. Using variables
            3. Public versus private
          3. Functions
            1. Update()
            2. OnMouseDown()
            3. Writing functions
          4. If else statements
              1. Multiple conditions
          5. Globals and dot syntax
              1. Using static to define globals
              2. Dot syntax
          6. Comments
          7. Further reading
      4. The FPSWalker script
          1. Launching the script
              1. Mac FPSWalker in Unitron
              2. Windows PC— FPSWalker in Uniscite
          2. Deconstructing the script
            1. Variable declaration
            2. Storing movement information
            3. Moving the character
            4. Checking grounded
            5. @Script commands
      5. Summary
    9. 4. Interactions
      1. Exploring collisions
      2. Ray casting
          1. The frame miss
          2. Predictive collision detection
      3. Adding the outpost
          1. Positioning
          2. Scaling
          3. Colliders and tagging the door
          4. Disabling automatic animation
      4. Opening the outpost
        1. Approach 1 Collision detection
          1. Creating new assets
          2. Scripting for character collision detection
            1. Working with OnControllerColliderHit
            2. Writing custom functions
              1. Declaring the function
              2. Playing audio
              3. Checking door status
              4. Playing animation
              5. Reversing the procedure
              6. Function efficiency
              7. Finishing the script
          3. Attaching the script
        2. Approach 2 Ray casting
          1. Disabling collision detection using comments
          2. Resetting the door collider
          3. Adding the ray
      5. Summary
    10. 5. Prefabs, Collection, and HUD
      1. Creating the battery prefab
        1. Download, import, and place
        2. Tagging the battery
        3. Scale, collider, and rotation
          1. Enlarging the battery
          2. Adding a trigger collider
          3. Creating a rotation effect
          4. Saving as a prefab
      2. Scattering batteries
      3. Displaying the battery GUI
        1. Creating the GUI Texture object
        2. Positioning the GUI Texture
        3. Scripting for GUI change
      4. Battery collection with triggers
      5. Restricting outpost access
        1. Restricting access
          1. Utilizing GetComponent()
        2. Hints for the player
          1. Battery GUI hint
          2. GUI Text hint
          3. Using fonts
      6. Summary
    11. 6. Instantiation and Rigid Bodies
      1. Introducing instantiation
        1. In concept
        2. In code
          1. Passing in an object
          2. Position and rotation
      2. Introducing rigid bodies
        1. Forces
        2. The Rigidbody component
      3. Making the minigame
        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 coconut throws
          1. Checking for player input
          2. Playing feedback sound
          3. Instantiating the coconut
          4. Naming instances
          5. Assigning velocity
            1. Ensuring component presence
          6. Safeguarding collisions
            1. Including the Audio Source component
        4. Script and variable assignment
        5. Instantiate restriction and object tidying
          1. Activating coconut throw
          2. Removing coconuts
        6. Adding the coconut shy platform
          1. Import settings
            1. The platform
            2. Targets and coconut collisions
          2. Placement
          3. Coconut detection script
            1. Establishing variables
            2. Collision detection
            3. Resetting the target
            4. Including audio source
          4. Script assignment
          5. Making more targets
        7. Winning the game
          1. Variable setup
          2. Checking for a win
          3. Script assignment
          4. Incrementing and decrementing targets
            1. Adding
            2. Subtracting
        8. Finishing touches
          1. Adding the crosshair
            1. Toggling the crosshair GUI Texture
          2. Informing the player
      4. Summary
    12. 7. Particle Systems
      1. What is a particle system?
        1. Particle emitter
        2. Particle Animator
        3. Particle Renderer
          1. In summary
      2. Making the task
        1. Asset download
        2. Adding the log pile
        3. Creating the fire particle systems
          1. Making 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. Making smoke
            1. Ellipsoid Particle Emitter settings
            2. Particle Animator settings
            3. Particle Renderer settings
            4. Positioning
          3. Adding audio to the fire
        4. Lighting the fire
          1. Adding the matches
          2. Creating the Matches GUI
          3. Collecting the matches
          4. Setting fire
      3. Testing and confirming
      4. Summary
    13. 8. Menu Design
      1. Interfaces and menus
        1. Making the main menu
          1. Creating the scene
            1. Visual example
            2. Duplicating the island
              1. Grouping the environment objects
              2. Duplicating the scene
          2. Cancelling mip mapping
          3. Adding titling
            1. GUI Texture formats
            2. Object creation
            3. Positioning
      2. Creating the menu approach 1
        1. Adding the play button
          1. GUI Texture button script
          2. Assigning public member variables
            1. Testing the button
          3. Adding the instructions button
          4. Adding the quit button
          5. Using debug commands to check scripts
      3. Creating the menu approach 2
        1. Disabling Game Objects
        2. Writing an OnGUI() script for a simple menu
          1. Fixed versus layout
          2. Public member variables
          3. The OnGUI() function
          4. Flexible positioning for GUIs
          5. Adding UnityGUI buttons
          6. Opening scenes with custom functions
            1. Applying and styling
          7. GUI skin settings
        3. Decision time
      4. Summary
    14. 9. Finishing Touches
      1. Volcano!
        1. Positioning the particle system
        2. Downloading assets
        3. Making the smoke material
        4. Particle system settings
          1. Ellipsoid Particle Emitter settings
          2. Particle Animator settings
        5. Adding audio to the volcano
        6. Volcano testing
      2. Coconut trails
        1. Editing the Prefab
        2. Trail Renderer component
        3. Updating the prefab
      3. Performance tweaks
        1. Camera Clip Planes and fog
        2. Ambient lighting
      4. Instructions scene
        1. Adding screen text
        2. Text Animation using Linear Interpolation (Lerp)
        3. Menu return
      5. Island level fade-in
        1. UnityGUI texture rendering
      6. Game win notification
      7. Summary
    15. 10. Building and Sharing
      1. Build Settings
        1. Web Player
          1. Player Settings
        2. Web Player Streamed
        3. OS X Dashboard Widget
        4. OS X/Windows Standalone
      2. Building the game
        1. Adapting for web build
            1. Quit button platform automation
        2. Texture compression and debug stripping
        3. Building standalone
          1. Indie versus Pro
        4. Building for the Web
          1. Adapting web player builds
            1. Detection script <HEAD>
            2. Object embed <BODY>
      3. Quality Settings
      4. Player Input settings
      5. Sharing your work
      6. Summary
    16. 11. Testing and Further Study
      1. Testing and finalizing
        1. Public testing
          1. Frame rate feedback
          2. Boosting performance
      2. Approaches to learning
        1. Cover as many bases as possible
        2. If you don't know, just ask!
      3. Summary