O'Reilly logo

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

Unity 3.x Game Development by Example

Book Description

A seat-of-your-pants manual for building fun, groovy little games quickly with Unity 3.x

  • Build fun games using the free Unity game engine even if you've never coded before
  • Learn how to "skin" projects to make totally different games from the same file – more games, less effort!
  • Deploy your games to the Internet so that your friends and family can play them
  • Packed with ideas, inspiration, and advice for your own game design and development
  • Stay engaged with fresh, fun writing that keeps you awake as you learn
  • Updated for the latest 3.x release

In Detail

Beginner game developers are wonderfully optimistic, passionate, and ambitious. But that ambition is often dangerous! Too often, budding indie developers and hobbyists bite off more than they can chew. Some of the most popular games in recent memory – Doodle Jump, Paper Toss, and Canabalt, to name a few – have been fun, simple games that have delighted players and delivered big profits to their creators. This is the perfect climate for new game developers to succeed by creating simple games with Unity.

This book starts you off on the right foot, emphasizing small, simple game ideas and playable projects that you can actually finish. The complexity of the games increases gradually as we progress through the chapters. The chosen examples help you learn a wide variety of game development techniques. With this understanding of Unity and bite-sized bits of programming, you can make your own mark in the game industry by finishing fun, simple games.

Unity 3.x Game Development by Example shows you how to build crucial game elements that you can reuse and re-skin in many different games, using the phenomenal (and free!) Unity 3D game engine. It initiates you into indie game culture by teaching you how to make your own small, simple games using Unity3D and some gentle, easy-to-understand code. It will help you turn a rudimentary keep-up game into a madcap race through hospital hallways to rush a still-beating heart to the transplant ward, program a complete 2D game using Unity's User Interface controls, put a dramatic love story spin on a simple catch game, and turn that around into a classic space shooter with spectacular explosions and "pew" sounds! By the time you're finished, you'll have learned to develop a number of important pieces to create your own games that focus in on that small, singular piece of joy that makes games fun.

Table of Contents

  1. Unity 3.x Game Development by Example
  2. Credits
  3. About the Author
  4. About the Reviewer
  5. www.PacktPub.com
    1. Support files, eBooks, discount offers and more
      1. Why Subscribe?
      2. Free Access for Packt account holders
  6. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Time for action – heading
      1. What just happened?
      2. Pop quiz heading
      3. Have a go hero heading
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  7. 1. That's One Fancy Hammer!
    1. Introducing Unity 3D
    2. Unity takes over the world
    3. Browser-based 3D? Welcome to the future
    4. Time for action – Install the Unity Web Player
    5. Welcome to Unity 3D!
      1. What can I build with Unity?
        1. FusionFall
      2. Completely hammered
      3. Should we try to build FusionFall?
      4. Another option
        1. Off-Road Velociraptor Safari
          1. Fewer features, more promise
          2. Maybe we should build Off-Road Velociraptor Safari?
      5. I bent my Wooglie
        1. Big Fun Racing
        2. Diceworks
    6. Walk before you can run (or double jump)
    7. There's no such thing as "finished"
    8. Stop! Hammer time
      1. Explore Bootcamp
    9. The wonders of technology!
    10. The Scene window
      1. The Game window
      2. The Hierarchy
        1. The Project panel
        2. The Inspector
        3. Heads up?
        4. Layers and layout dropdowns
        5. Playback controls
        6. Scene controls
    11. Don't stop there live a little!
    12. Summary
      1. Big ambition, tiny games
  8. 2. Let's Start with the Sky
    1. That little lightbulb
    2. The siren song of 3D
    3. Features versus content
    4. A game with no features
    5. Mechanic versus skin
    6. Trapped in your own skin
    7. That singular piece of joy
    8. One percent inspiration
    9. Motherload
    10. Heads up!
    11. Artillery Live!
    12. Pong
    13. The mechanic that launched a thousand games
      1. Have a go hero Redesign your favorite games
    14. Toy or story
      1. Pop Quiz Finding that singular piece of joy
    15. Redefining the sky
    16. Summary
      1. Let's begin
  9. 3. Game 1: Ticker Taker
    1. Kick up a new Unity project
      1. Where did everything go?
    2. 'Tis volley
    3. Keep the dream alive
    4. Slash and burn!
    5. The many faces of keep-up
    6. Creating the ball and the hitter
    7. Time for action – Creating the ball
      1. What just happened that's all there is to it?
    8. A ball by any other name
    9. Time for action – Renaming the ball
    10. Origin story
      1. XYZ/RGB
    11. Time for action – Moving the ball Into the "sky"
    12. Time for action – Shrinking the ball
    13. Time for action – Saving your scene
    14. Time for action – Adding the paddle
      1. What is a mesh?
      2. Poly wanna crack your game performance?
    15. Keeping yourself in the dark
    16. Time for action – Adding a light
    17. Time for action – Moving and rotating the light
      1. Have a go hero Let there be (additional) light
      2. Extra credit
    18. Are you a luminary?
      1. Who turned out the lights?
      2. Darkness reigns
    19. Time for action – Camera mania
    20. Time for action – Test your game
    21. Let's get physical
    22. Time for action – Adding physics to your game
    23. Understanding the gravity of the situation
    24. More bounce to the ounce
    25. Time for action – Make the ball bouncy
      1. Have a go hero DIY physic materials
    26. Summary
      1. Following the script
  10. 4. Code Comfort
    1. What is code?
    2. Time for action – Writing your first Unity script
    3. A leap of faith
    4. Lick it and stick it
      1. Disappear Me!
      2. What just happened?
    5. It's all Greek to me
    6. You'll never go hungry again
    7. With great sandwich comes great responsibility
    8. Examining the code
    9. Time for action – Find the Mesh Renderer component
    10. Time for action – Make the ball re-appear
    11. Ding!
    12. Time for action – Journey to the Unity Script Reference
    13. The Renderer class
      1. Have a go hero - Pulling the wings off of flies
    14. What's another word for "huh"?
    15. It's been fun
    16. Time for action – Unstick the script
    17. Gone, but not forgotten
    18. Why code?
    19. Equip your baby bird
    20. Time for action – Creating a new MouseFollow script
      1. What just happened?
    21. A capital idea
    22. Animating with code
    23. Time for action – Animating the paddle
      1. What just happened - what witchcraft is this?
      2. What just happened why didn't the paddle animate before?
    24. Pick a word (almost) any word
    25. Screen coordinates versus world coordinates
    26. Move the paddle
    27. Worst. Game. Ever.
    28. See the matrix
    29. Time for action – Listening to the paddle
    30. A tiny bit o' math
    31. Tracking the numbers
    32. Futzing with the numbers
    33. Time for action – Logging the new number
    34. She's A-Work!
    35. Somebody get me a bucket
    36. Time for action – Declaring a variable to store the screen midpoint
      1. What just happened we've gone too Var
    37. Using all three dees
    38. Time for action – Following the Y position of the mouse
    39. A keep-up game for robots
    40. Once more into the breach
    41. Time for action – Re-visiting the Unity Language Reference
    42. Our work here is done
    43. Time for action – Adding the sample code to your script
    44. One final tweak
      1. What's a quaternion?
      2. Wait, what's a quaternion?
      3. WHAT THE HECK IS A QUATERNION??
    45. Educated guesses
      1. More on Slerp
    46. Right on target
      1. Have a go hero - Time to break stuff
    47. Keep it up
      1. Beyond the game mechanic
  11. 5. Game #2: Robot Repair
    1. You'll totally flip
    2. A blank slate
    3. You're making a scene
    4. Time for action – Setting up two scenes
    5. No right answer
    6. Time for action – Preparing the GUI
    7. The beat of your own drum
    8. Time for action – Creating and linking a custom GUI skin
      1. What just happened?
    9. Time for action – Creating a button UI control
      1. What just happened?
      2. Have a go hero No sense sitting around on your button
    10. Want font?
    11. Cover your assets
    12. Time for action – Nix the mip-mapping
    13. Front and center
    14. Time for action – Centering the button
      1. What just happened investigating the code
    15. To the game!
    16. Time for action – Adding both scenes to the Build List
    17. Set the stage for robots
    18. Time for action – Preparing the game scene
    19. The game plan
    20. Have some class!
    21. Time for action – Storing the essentials
    22. Start me up
    23. Going loopy
    24. The anatomy of a loop
    25. To nest is best
    26. Seeing is believing
    27. Time for action – Creating an area to store the grid
      1. Have a go hero Don't take my word for it!
    28. Build that grid
      1. What just happened grokking the code
    29. Now you're playing with power!
  12. 6. Game #2: Robot Repair Part 2
    1. From zero to game in one chapter
    2. Finding your center
    3. Time for action – Centering the game grid vertically
      1. What just happened?
    4. Time for action – Centering the game grid horizontally
      1. What just happened coding like a ninja
    5. Down to the nitty griddy
      1. Do the random card shuffle
    6. Time for action – Preparing to build the deck
      1. Let's break some robots
    7. Time for action – Building the deck
      1. What just happened dissecting the bits
    8. Time for action – Modifying the img argument
      1. What just happened?
    9. What exactly is "this"?
      1. Have a go hero - Grokketh-thou Random.Range()?
    10. Random reigns supreme
    11. Second dragon down
    12. Time to totally flip
    13. Time for action – Making the cards two-sided
    14. Time for action – Building the card-flipping function
    15. Time for action – Building the card-flipping function
      1. What just happened dissecting the flip
    16. Pumpkin eater
      1. What just happened?
    17. Stabby McDragonpoker rides again
    18. Game and match
    19. Time for action – ID the cards
      1. What just happened?
    20. Time for action – Comparing the IDs
      1. What just happened?
    21. On to the final boss
      1. Endgame
    22. Time for action – Checking for victory
      1. What just happened?
      2. Have a go hero Extra credit
      3. Endgame
    23. Bring. It. On.
  13. 7. Don't Be a Clock Blocker
    1. Apply pressure
    2. Time for action – Preparing the clock script
    3. Time for more action Preparing the clock text
    4. Still Time for action – Changing the clock text color
    5. Time for action – rides again Creating a font texture and material
    6. Time for action – What's with the tiny font?
      1. What just happened - was that seriously magic?
    7. Time for action – Preparing the clock code
      1. What just happened that's a whole lotta nothing
    8. Time for action – Creating the countdown logic
    9. Time for action – Displaying the time onscreen
      1. What just happened what about that terrifying code?
    10. Picture it
    11. Time for action – Grabbing the picture clock graphics
      1. What just happened you can do that?
    12. Time for action – Flexing those GUI muscles
      1. What just happened how does it work?
    13. The incredible shrinking clock
    14. Keep your fork there's pie!
      1. Pop quiz How do we build it?
    15. How they did it
    16. Time for action – Rigging up the textures
    17. Time for action – Writing the pie chart script
      1. What just happened?
    18. Time for action – Commencing operation pie clock
      1. What just happened explaining away the loose ends
    19. Time for action – Positioning and scaling the clock
      1. Have a go hero Rock out with your clock out
    20. Unfinished business
  14. 8. Ticker Taker
    1. Welcome to Snoozeville
      1. Model behavior
    2. Time for action – Exploring the models
    3. Time for action – Hands up!
      1. What just happened size matters
    4. Time for action – Changing the FBX import scale settings
    5. Time for action – Making the mesh colliders convex
    6. Time for action – Making the hands and tray follow the mouse
      1. What just happened monkey see, monkey do
    7. Time for action – Get your heart on
    8. Time for action – Ditch the ball and paddle
      1. What just happened bypass the aorta
    9. Time for action – Material witness
      1. What just happened understanding Materials
      2. Have a go hero Adding Materials to the other models
    10. This just in: this game blows
    11. Time for action – Multiple erections
    12. Time for action – Creating a font texture
    13. Time for action – Creating the HeartBounce script
      1. What just happened charting a collision course
    14. Time for action – Tagging the tray
    15. Time for action – Tweak the bounce
      1. What just happened storing velocity
    16. Time for action – Keeping track of the bounces
    17. Time for action – Adding the lose condition
      1. What just happened understanding the code
    18. Time for action – Adding the Play Again button
      1. What just happened?
      2. Ticker taken
  15. 9. Game #3: The Break-Up
    1. Time for action – Bombs away!
    2. Time for action – Poke those particles
    3. Time for action – Creating a spark material
      1. Have a go hero Time to ignite your creative spark
    4. Time for action – Prefabulous
      1. What just happened what's a Prefab?
    5. Time for action – Lights, camera, apartment
    6. Time for action – Adding the character
    7. Time for action – Registering the animations
    8. Time for action – Scripting the character
      1. What just happened stepping through the "step" code
    9. Time for action – Opening the pod bay door, Hal
    10. Time for action – Collision-enable the character
    11. Time for action – Re-prefab the prefab
    12. Time for action – Apocalypse now?
    13. Time for action – Go boom
    14. Time for action – The point of impact
    15. Time for action – Hook up the explosion
    16. Summary
  16. 10. Game #3: The Break-Up Part 2
    1. Time for action – Amass some glass
    2. Time for action – Creating a Particle System
      1. What just happened getting smashed
    3. Time for action – Making it edgier!
      1. What just happened I fall to pieces
    4. Time for action – Containing the explosion
      1. What just happened duped?
    5. Time for action – Let's get lazy
      1. What just happened FallingObject: The PuppetMaster
    6. Very variable?
    7. Terminal velocity is a myth bombs fall faster
      1. What just happened when Game Objects collide?
    8. Time for action – Tagging the objects
    9. Time for action – Writing the collision detection code
    10. Time for action – Animation interrupts
      1. What just happened the impenetrable stare
    11. Time for action – Adding facial explosions
      1. What just happened raindrops keep 'sploding on my head
    12. Time for action – Making some noise
    13. Time for action – Adding sounds to the FallingObjectScript
    14. What's the catch?
      1. Have a go hero Sound off
    15. Time for action – Mixing it up a bit
      1. Have a go hero Filling in the gaps
    16. Summary
  17. 11. Game #4: Shoot the Moon
    1. Time for action – Duplicating your game project
    2. Time for action – Spacing this sucker up a bit
    3. Time for action – Enter the hero
    4. Time for action – It's a hit!
    5. Time for action – Bring on the bad guys
    6. Time for action – Do some housekeeping
    7. Time for action – Fixing the fall
    8. Time for action – Tweak the hero
      1. What just happened hooray for lazy!
    9. Time for action – Give up the func
    10. Time for action – Itchy trigger finger
    11. Time for action – Futurize the bullet
    12. Time for action – Building Halo
    13. Time for action – Fire!
    14. Time for action – Code do-si-do
      1. What just happened eat lead
    15. Time for action – The maaagic of aaaarguments
    16. Time for action – Adding the most important part of any space shooter
      1. Last year's model
      2. Have a go hero Filling in the empty space
    17. Summary
    18. More hospitality
  18. 12. Action!
    1. Open heart surgery
    2. Time for action – Haul in the hallway
    3. Time for action – Meet me at camera two
    4. Time for action – Adjusting the Main Camera
    5. Time for action – Deck the halls
    6. Time for action – Turn on the lights
    7. Time for action – Setting up the camera rig
    8. Time for action – Animating the bouncer
      1. What just happened red and raging
    9. Time for action – I like to move it, move it
      1. Have a go hero Bounce your brains out
    10. Time for action – Animating the runner
      1. What just happened holy hospital rampage, Batman!
    11. Time for action – How to "handle" Nurse Slipperfoot
    12. Time for action – You spin me right round
      1. Have a go hero Give Robo-Nurse a soul
      2. Have a go hero Use your new-found powers for good
    13. Time for action – Deploying your game
    14. Time to grow
    15. Beyond the book
  19. A. References
    1. Online resources
    2. Offline resources
    3. Free development tools
      1. Graphics
      2. Sound
    4. Content sites
    5. Game portals