You are previewing Unity 4.x Game Development by Example Beginner's Guide.
O'Reilly logo
Unity 4.x Game Development by Example Beginner's Guide

Book Description

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

  • Learn the basics of the Unity 3D game engine by building five small, functional game projects

  • Explore simplification and iteration techniques that will make you more successful as a game developer

  • Take Unity for a spin with a refreshingly humorous approach to technical manuals

In Detail

Unity is one of the biggest game engines in the world, providing the user with a range of important tools that they need to bring their ideas into reality. Beginner game developers are optimistic, passionate, and ambitious, but that ambition can be dangerous! Too often, budding indie developers and hobbyists bite off more than they can chew. Games like Angry Birds, Cut the Rope, and Fruit Ninja are 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, starting today.

This book teaches you the ins and outs of the unique Unity game engine interface. Clear and concise code examples written in both Unity Javascript and C# take you through the step-by-step process of building five small, functional games. With this understanding you can start making your own mark on the game industry!

With absolutely no programming or game development experience, you will learn how to build five simple games in Unity by following step-by-step instructions, peppered with amusing analogies and anecdotes from an experienced indie developer. Following a primer on simplifying your game ideas to that single “something” that keeps players coming back for more, dive into the Unity game engine by creating a simple bat-and-ball game. From there, you'll build a complete memory game using only the Unity GUI system. After building a 2.5D mouse avoider game, you'll learn how to re-skin the project to completely change the game's theme. Incorporating everything you've learned, you'll return to complete the bat-and-ball game by adding scoring, replay flow, sound effects, and animations. Finally, in the new bonus chapter, you'll program some simple AI (Artificial Intelligence) for a tic tac toe game.

"Unity 4.x Game Development by Example" is a fun and light-hearted exploration of one of the most powerful game engines on the market today. Find out what all the fuss is about by getting up to speed using this book!

Table of Contents

  1. Unity 4.x Game Development by Example Beginner's Guide
    1. Table of Contents
    2. Unity 4.x Game Development by Example Beginner's Guide
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. A word about the third edition
      2. Your future as a game developer
      3. What this book covers
      4. What you need for this book
      5. Who this book is for
      6. Conventions
      7. Reader feedback
      8. Customer support
        1. Downloading the color images of this book
        2. Downloading the example code
        3. Errata
        4. Piracy
        5. Questions
    8. 1. That's One Fancy Hammer!
      1. Introducing Unity 3D
      2. The engine, the tool, and the all-weather tires
      3. Unity takes over the world
      4. Why choose Unity?
      5. Why burn this book and run away screaming?
      6. Browser-based 3D – welcome to the future
      7. Time for action – install the Unity Web Player
      8. Welcome to Unity 3D!
      9. What can I build with Unity?
        1. FusionFall
      10. Completely hammered
      11. Should we try to build FusionFall?
      12. Another option
        1. Off-Road Velociraptor Safari
        2. Fewer features, more promises
        3. Maybe we should build Off-Road Velociraptor Safari?
      13. I bent my Wooglie
        1. Big Fun Racing
        2. Diceworks
        3. Lovers in a Dangerous Spacetime
        4. Showcase Showdown
      14. Unity Technologies – "Made with Unity" page
      15. Kongregate
      16. The iOS App Store
      17. Walk before you can run (or double jump)
      18. There's no such thing as "finished"
      19. Stop! Hammer time
        1. Fight Some Angry Bots
      20. The wonders of technology!
      21. The Scene window
        1. The Game window
        2. The Hierarchy panel
        3. The Project panel
        4. The Inspector panel
        5. Heads Up?
        6. Layers and layout dropdowns
        7. Playback controls
        8. Scene controls
      22. Don't stop there – live a little!
      23. Summary
        1. Big ambition, tiny games
    9. 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
        1. Possible additional features:
      10. Heads up!
      11. Artillery Live!
        1. The skinny on multiplayer
        2. Bang for your buck
      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
    10. 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 – create the Ball
        1. What just happened – that's all there is to it?
      8. A ball by any other name
      9. Time for action – rename the Ball
      10. Origin story
        1. XYZ/RGB
      11. Time for action – move the Ball Into the "Sky"
      12. Time for action – shrink the Ball
      13. Time for action – save your scene
      14. Time for action – add the Paddle
        1. What's a Mesh?
        2. Poly wants to crack your game performance?
      15. Keeping yourself in the dark
      16. Time for action – add a light
      17. Time for action – move and rotate the light
        1. Have a go hero
        2. Extra credit
      18. Are you a luminary?
        1. Who turned out the lights?
        2. Darkness reigns
        3. Cameramania
      19. Time for action – test your game
      20. Let's get physical
      21. Add physics to your game
      22. Understanding the gravity of the situation
      23. More bounce to the ounce
      24. Time for action – make the Ball bouncy
        1. Have a go hero
      25. Summary
        1. Following the script
    11. 4. Code Comfort
      1. What is code?
      2. Time for action – write 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 – create a new MouseFollow Script
        1. What just happened?
      21. A capital idea
      22. Animating with code
      23. Time for action – animate the Paddle
        1. What just happened – what witchcraft is this?
      24. Why didn't the Paddle animate before?
      25. Pick a word – (almost) any word
      26. Screen coordinates versus World coordinates
      27. Move the Paddle
      28. Worst. Game. Ever.
      29. See the matrix
      30. Time for action – listen to the paddle
      31. A tiny bit o' math
      32. Tracking the numbers
      33. Futzing with the numbers
      34. Time for action – Log the New Number
      35. She's a-work!
      36. Somebody get me a bucket
      37. Time for action – declare a variable to store the Screen midpoint
        1. What just happened – we've gone too var
      38. Using all three dees
      39. Time for action – follow the y position of the mouse
      40. A keep-up game for robots
      41. Once more into the breach
      42. Time for action – re-visit the Unity Language Reference
      43. Our work here is done
      44. Time for action – add the sample code to your Script
      45. One final tweak
        1. What's a quaternion?
        2. Wait, what's a quaternion?
        3. WHAT THE HECK IS A QUATERNION??
      46. Educated guesses
        1. More on Slerp
      47. Right on target
        1. Have a go hero – time to break stuff
      48. Keep it up
        1. Beyond the game mechanic
      49. C# Addendum
    12. 5. Game #2 – Robot Repair
      1. You'll totally flip
      2. A blank slate
      3. You're making a scene
      4. Time for action – set up two scenes
      5. No right answer
      6. Time for action – prepare the GUI
      7. The beat of your own drum
      8. Time for action – create and link a custom GUI skin
        1. What just happened?
      9. Time for action – create 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 – center the button
        1. What just happened – investigating the code
      15. The waiting game
      16. The easiest button to button
      17. To the game!
      18. Time for action – add both scenes to Build List
      19. Set the stage for robots
      20. Time for action – prepare the game scene
      21. The game plan
      22. Have some class!
      23. Time for action – store the essentials
      24. A matter of great import
      25. Building a better bucket
      26. How big is your locker?
      27. Start me up
      28. Going loopy
      29. The anatomy of a loop
      30. To nest is best
      31. Seeing is believing
      32. Time for action – create an area to store the grid
        1. Have a go hero – don't take my word for it!
      33. Build that grid
        1. What just happened – grokking the code
      34. Now you're playing with power!
      35. C# addendum
    13. 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.
      24. C# Addendum
    14. 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 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 on-screen
        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 – Flex 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
      21. C# Addendum
    15. 8. Hearty Har Har
      1. Welcome to Snoozeville
      2. Model behavior
      3. Time for action – exploring the models
      4. Time for action – hands up!
        1. What just happened – size matters
      5. Time for action – changing the FBX import scale settings
      6. Time for action – making the mesh colliders convex
      7. Time for action – making the hands and tray follow the mouse
        1. What just happened – monkey see, monkey do
      8. Time for action – getting your heart on
      9. Time for action – ditching the Ball and Paddle
        1. What just happened – bypass the aorta
      10. Time for action – material witness
        1. What just happened – understanding Materials
        2. Have a go hero – adding materials to the other models
      11. This just in – this game blows
      12. Time for action – multiple erections
      13. Time for action – creating a font texture
      14. Time for action – create the HeartBounce script
        1. What just happened – charting a collision course
      15. Time for action – tagging the tray
      16. Time for action – tweaking the bounce
        1. What just happened – storing velocity
      17. Time for action – keeping track of the bounces
      18. Time for action – adding the lose condition
        1. What just happened – understanding the code
      19. Time for action – adding the Play Again button
        1. What just happened?
      20. Ticker taken
      21. C# Addendum
    16. 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, and 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 – open the pod bay door, Hal
      10. Time for action – collision-enable the character
      11. Time for action – apocalypse now?
      12. Time for action – go boom
      13. Time for action – kill kill murder die
      14. Time for action – the point of impact
      15. Time for action – hook up the explosion
      16. Summary
      17. C# addendum
    17. 10. Game #3 – The Break-Up Part 2
      1. Time for action – amass some glass
      2. Time for action – create a particle system
        1. What just happened – getting smashed
      3. Time for action – make it edgier!
        1. What just happened – I fall to pieces
      4. Time for action – contain 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 – tag the objects
      9. Time for action – write the collision detection code
      10. Time for action – animation interrupts
        1. What just happened – the impenetrable stare
      11. Time for action – add facial explosions
        1. What just happened – raindrops keep 'sploding on my head
      12. Time for action – make some noise
      13. Time for action – add sounds to FallingObject
      14. Silent 'Splosion
      15. What's the catch?
        1. Have a go hero – sound off
      16. Time for action – mix it up a bit
        1. Have a go hero – filling in the gaps
      17. Summary
      18. C# Addendum
    18. 11. Game #4 – Shoot the Moon
      1. Time for action – duplicate your game project
      2. Time for action – space the shooter 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 – add 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. C# Addendum
    19. 12. Game #5 – Kisses 'n' Hugs
      1. Computers that think
      2. Time for action – haul in the hallway
      3. Time for action – hash it out
      4. One Script to rule them all
      5. Time for action – it's hip to be square
        1. What just happened – find and click
      6. Squaring the Square
      7. Time for action – now you see it...
      8. Family values
      9. Time for action – X marks the spot
      10. Time for action – boy O boy
      11. Time for action – bottoming out
      12. Here comes the drop
        1. What just happened – to collide or not to collide?
      13. Time for action – +9 accuracy
      14. Time for action – solve for X
        1. What just happened – lockdown
      15. Time for action – it takes two to Tic Tac Toe
        1. What just happened – alternating between players
      16. Time for action – designer to player. Come in, player.
        1. What just happened – prompt service
      17. Slowly building to a climax
        1. Have a go hero – think it through
      18. Read after thinking
        1. What just happened – building a more complex lock
      19. On deaf ears
      20. Time for action – pretty maids all in a row
        1. What just happened – order!
      21. Winner is coming
      22. Codesplosion
      23. Need-to-know basis
      24. Need-to-know basis
      25. Clean-up on aisle code
        1. What just happened – vending machine
      26. Shave and a haircut
        1. What just happened – hunting for a win
      27. Time for action – check for a win
      28. Sore loser
      29. Time for action – notify the winner
      30. Time for action – you win. Now what?
        1. Have a go hero – draw, pardner
      31. Nice moves
      32. Time for action – the final bug
      33. All done but for the shouting
      34. C# addendum
    20. 13. AI Programming and World Domination
      1. Take it away, computer
      2. Time for action – add computer control
      3. Herpa derp derp
        1. What just happened – making a list, checking it twice
      4. Unpacking the code
      5. Time for action – code consolidation
      6. Tic Tac Toe at the speed of light
      7. Sore loser
      8. Click-spamming for fun and profit
      9. Artificial stupidity
        1. Have a go hero – solve Tic Tac Toe
      10. Time for action – winning is everything
      11. It's a trap!
      12. The leftovers
      13. Time for action – pseu pseu pseudocode
        1. What just happened – stepping through the strategy
      14. Time for action – begin at the end
      15. Time for action – the final four
      16. Code one, get one free
        1. Have a go hero - stump the author
      17. The actual intelligence behind artificial intelligence
      18. Time for action – score!
        1. What just happened – the search is on
        2. Shut your trap
        3. Detecting the tri-corner trap
      19. Time for action – to catch a competitor
        1. What just happened – I'm running out of trap puns
        2. Perfection Horrible, horrible perfection.
      20. Time for action – programming fallibility
        1. What just happened – roll for initiative
        2. Turning it up to "Smart"
        3. Code encore
      21. Summary
        1. More hospitality
      22. C# addendum
    21. 14. 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 – adjust Main Camera
      5. Time for action – deck the halls
      6. Time for action – turn on the lights
      7. Time for action – set up the camera rig
      8. Time for action – animate 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 – animate 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 – deploy your game
      14. Time to grow
      15. Beyond the book
    22. A. Appendix
      1. Online resources
      2. Offline resources
      3. Free development tools
        1. Graphics
        2. Sound
      4. The Unity Asset Store
      5. Game portals
    23. Index