Ryan Henson Creighton - Unity 4.x Game Development by Example Beginner's Guide

Скачать

Ryan Henson Creighton - Unity 4.x Game Development by Example Beginner's Guide

Unity 4.x Game Development by Example

Beginner's Guide

Год: 2013

Автор: Ryan Henson Creighton

Жанр: CG Game Development

Издательство: Packt Publishing

ISBN: 978-1-84969-526-8

Язык: Английский

Формат: PDF

Качество: Изначально компьютерное (eBook)

Интерактивное оглавление: Да

Количество страниц: 572

Описание: 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!

What you will learn from this book

Explore the basic development flow of the Unity 3D game engine

Understand fundamental programming concepts in both javascript and C#

Develop five different games from inception to completion

Discover the secrets new game developers use to be successful when they're just starting out

Grasp the nuances of Unity's immediate-mode GUI

Completely re-skin a game for fun and (potentially) profit

Lengthen gameplay by learning how to use random numbers

Explore the process of writing Artificial Intelligence from scratch

Chapter 1: That's One Fancy Hammer! 9

Introducing Unity 3D 9

The engine, the tool, and the all-weather tires 10

Unity takes over the world 11

Why choose Unity? 11

Why burn this book and run away screaming? 12

Browser-based 3D – welcome to the future 13

Time for action – install the Unity Web Player 13

Welcome to Unity 3D! 14

What can I build with Unity? 14

FusionFall 14

Completely hammered 15

Should we try to build FusionFall? 15

Another option 16

Off-Road Velociraptor Safari 16

Fewer features, more promises 17

Maybe we should build Off-Road Velociraptor Safari? 17

I bent my Wooglie 17

Big Fun Racing 18

Diceworks 18

Lovers in a Dangerous Spacetime 20

Showcase Showdown 20

Unity Technologies – "Made with Unity" page 21

Kongregate 21

The iOS App Store 22

Table of Contents

[ ii ]

Walk before you can run (or double jump) 22

There's no such thing as "finished" 23

Stop! Hammer time 23

Fight Some Angry Bots 24

The wonders of technology! 26

The Scene window 26

The Game window 27

The Hierarchy panel 28

The Project panel 29

The Inspector panel 30

Heads Up? 31

Layers and layout dropdowns 33

Playback controls 33

Scene controls 33

Don't stop there – live a little! 34

Summary 35

Big ambition, tiny games 35

Chapter 2: Let's Start with the Sky 37

That little lightbulb 38

The siren song of 3D 39

Features versus content 40

A game with no features 40

Mechanic versus skin 41

Trapped in your own skin 41

That singular piece of joy 42

One percent inspiration 42

Motherload 43

Possible additional features: 45

Heads up! 46

Artillery Live! 46

The skinny on multiplayer 50

Bang for your buck 51

Pong 52

The mechanic that launched a thousand games 54

Toy or story 56

Redefining the sky 58

Summary 59

Let's begin 59

Table of Contents

[ iii ]

Chapter 3: Game #1 – Ticker Taker 61

Kick up a new Unity project 62

Where did everything go? 63

'Tis volley 63

Keep the dream alive 64

Slash and burn! 64

The many faces of keep-up 65

Creating the ball and the hitter 65

Time for action – create the Ball 66

A ball by any other name 67

Time for action – rename the Ball 68

Origin story 68

XYZ/RGB 70

Time for action – move the Ball Into the "Sky" 70

Time for action – shrink the Ball 71

Time for action – save your scene 72

Time for action – add the Paddle 73

What's a Mesh? 75

Poly wants to crack your game performance? 78

Keeping yourself in the dark 78

Time for action – add a light 79

Time for action – move and rotate the light 80

Extra credit 83

Are you a luminary? 84

Who turned out the lights? 84

Darkness reigns 84

Cameramania 85

Time for action – test your game 86

Let's get physical 87

Add physics to your game 87

Understanding the gravity of the situation 88

More bounce to the ounce 89

Time for action – make the Ball bouncy 89

Summary 92

Following the script 93

Chapter 4: Code Comfort 95

What is code? 95

Time for action – write your first Unity Script 96

A leap of faith 97

Table of Contents

[ iv ]

Lick it and stick it 99

Disappear me! 99

It's all Greek to me 100

You'll never go hungry again 101

With great sandwich comes great responsibility 102

Examining the code 103

Time for action – find the Mesh Renderer component 103

Time for action – make the ball re-appear 104

Ding! 105

Time for action – journey to the Unity Script Reference 105

The Renderer class 107

What's another word for "huh"? 110

It's been fun 111

Time for action – unstick the Script 111

Gone, but not forgotten 112

Why code? 113

Equip your baby bird 113

Time for action – create a new MouseFollow Script 113

A capital idea 115

Animating with code 116

Time for action – animate the Paddle 117

Why didn't the Paddle animate before? 118

Pick a word – (almost) any word 118

Screen coordinates versus World coordinates 119

Move the Paddle 120

Worst. Game. Ever. 121

See the matrix 121

Time for action – listen to the paddle 121

A tiny bit o' math 122

Tracking the numbers 123

Futzing with the numbers 124

Time for action – Log the New Number 124

She's a-work! 125

Somebody get me a bucket 125

Time for action – declare a variable to store the Screen midpoint 126

Using all three dees 128

Time for action – follow the y position of the mouse 129

A keep-up game for robots 129

Once more into the breach 130

Table of Contents

[ v ]

Time for action – re-visit the Unity Language Reference 130

Our work here is done 131

Time for action – add the sample code to your Script 131

One final tweak 133

What's a quaternion? 133

Wait, what's a quaternion? 133

WHAT THE HECK IS A QUATERNION?? 133

Educated guesses 134

More on Slerp 135

Right on target 136

Keep it up 137

Beyond the game mechanic 138

C# Addendum 138

Chapter 5: Game #2 – Robot Repair 143

You'll totally flip 144

A blank slate 145

You're making a scene 146

Time for action – set up two scenes 146

No right answer 147

Time for action – prepare the GUI 148

The beat of your own drum 149

Time for action – create and link a custom GUI skin 150

Time for action – create a button UI control 152

Want font? 156

Cover your assets 158

Time for action – nix the mip-mapping 159

Front and center 160

Time for action – center the button 161

The waiting game 162

The easiest button to button 162

To the game! 164

Time for action – add both scenes to Build List 165

Set the stage for robots 166

Time for action – prepare the game scene 167

The game plan 167

Have some class! 168

Time for action – store the essentials 170

A matter of great import 171

Table of Contents

[ vi ]

Building a better bucket 172

How big is your locker? 173

Start me up 174

Going loopy 175

The anatomy of a loop 175

To nest is best 176

Seeing is believing 177

Time for action – create an area to store the grid 178

Build that grid 179

Now you're playing with power! 181

C# addendum 182

Chapter 6: Game #2 – Robot Repair Part 2 187

From zero to game in one chapter 187

Finding your center 189

Time for action – centering the game grid vertically 189

Time for action – centering the game grid horizontally 192

Down to the nitty griddy 194

Do the random card shuffle 195

Time for action – preparing to build the deck 195

Let's break some robots 196

Time for action – building the deck 196

Time for action – modifying the img argument 200

What exactly is "this"? 202

Random reigns supreme 205

Second dragon down 205

Time to totally flip 205

Time for action – making the cards two-sided 206

Time for action – building the card-flipping function 207

Time for action – building the card-flipping function 210

Pumpkin eater 212

Stabby McDragonpoker rides again 213

Game and match 213

Time for action – ID the cards 213

Time for action – comparing the IDs 214

On to the final boss 217

Endgame 218

Time for action – checking for victory 218

Endgame 221

Bring. It. On. 222

C# Addendum 228

Table of Contents

[ vii ]

Chapter 7: Don't Be a Clock Blocker 235

Apply pressure 236

Time for action – preparing the Clock Script 236

Time for more action – preparing the clock text 237

Still time for action – changing the clock text color 238

Time for action rides again – creating Font Texture and Material 240

Time for action – what's with the tiny font? 244

Time for action – preparing the clock code 245

Time for action – creating the countdown logic 246

Time for action – displaying the time on-screen 248

Picture it 251

Time for action – grabbing the picture clock graphics 251

Time for action – Flex those GUI muscles 253

The incredible shrinking clock 257

Keep your fork – there's pie! 258

How they did it 258

Time for action – rigging up the textures 260

Time for action – writing the pie chart script 261

Time for action – commencing operation pie clock 264

Time for action – positioning and scaling the clock 267

Unfinished business 269

C# Addendum 270

Chapter 8: Hearty Har Har 275

Welcome to Snoozeville 276

Model behavior 276

Time for action – exploring the models 277

Time for action – hands up! 280

Time for action – changing the FBX import scale settings 281

Time for action – making the mesh colliders convex 282

Time for action – making the hands and tray follow the mouse 284

Time for action – getting your heart on 284

Time for action – ditching the Ball and Paddle 287

Time for action – material witness 288

This just in – this game blows 293

Time for action – multiple erections 293

Time for action – creating a font texture 296

Time for action – create the HeartBounce script 297

Time for action – tagging the tray 298

Time for action – tweaking the bounce 300

Table of Contents

[ viii ]

Time for action – keeping track of the bounces 301

Time for action – adding the lose condition 303

Time for action – adding the Play Again button 305

Ticker taken 307

C# Addendum 307

Chapter 9: Game #3 – The Break-Up 311

Time for action – bombs away! 313

Time for action – poke those particles 316

Time for action – creating a spark material 318

Time for action – prefabulous 321

Time for action – lights, camera, and apartment 324

Time for action – adding the character 325

Time for action – registering the animations 326

Time for action – scripting the character 328

Time for action – open the pod bay door, Hal 330

Time for action – collision-enable the character 331

Time for action – apocalypse now? 332

Time for action – go boom 333

Time for action – kill kill murder die 336

Time for action – the point of impact 337

Time for action – hook up the explosion 338

Summary 339

C# addendum 339

Chapter 10: Game #3 – The Break-Up Part 2 343

Time for action – amass some glass 343

Time for action – create a particle system 344

Time for action – make it edgier! 346

Time for action – contain the explosion 348

Time for action – let's get lazy 349

Very variable? 351

Terminal velocity is a myth – bombs fall faster 351

Time for action – tag the objects 353

Time for action – write the collision detection code 354

Time for action – animation interrupts 355

Time for action – add facial explosions 356

Time for action – make some noise 357

Time for action – add sounds to FallingObject 358

Silent 'Splosion 360

Table of Contents

[ ix ]

What's the catch? 360

Time for action – mix it up a bit 362

Summary 365

C# Addendum 365

Chapter 11: Game #4 – Shoot the Moon 369

Time for action – duplicate your game project 370

Time for action – space the shooter up a bit 371

Time for action – enter the hero 376

Time for action – it's a hit! 378

Time for action – bring on the bad guys 381

Time for action – do some housekeeping 383

Time for action – fixing the fall 384

Time for action – tweak the hero 386

Time for action – give up the func 388

Time for action – itchy trigger finger 391

Time for action – futurize the bullet 392

Time for action – building Halo 393

Time for action – fire! 396

Time for action – code do-si-do 397

Time for action – the maaagic of aaaarguments 399

Time for action – add the most important part of any space shooter 400

Last year's model 402

Summary 403

C# Addendum 403

Chapter 12: Game #5 – Kisses 'n' Hugs 407

Computers that think 407

Time for action – haul in the hallway 409

Time for action – hash it out 410

One Script to rule them all 413

Time for action – it's hip to be square 413

Squaring the Square 415

Time for action – now you see it... 417

Family values 418

Time for action – X marks the spot 418

Time for action – boy O boy 420

Time for action – bottoming out 421

Here comes the drop 422

Time for action – +9 accuracy 424

Table of Contents

[ x ]

Time for action – solve for X 426

Time for action – it takes two to Tic Tac Toe 426

Time for action – designer to player. Come in, player. 428

Slowly building to a climax 431

Read after thinking 431

On deaf ears 433

Time for action – pretty maids all in a row 433

Winner is coming 437

Codesplosion 437

Need-to-know basis 438

Need-to-know basis 438

Clean-up on aisle code 439

Shave and a haircut 440

Time for action – check for a win 441

Sore loser 442

Time for action – notify the winner 443

Time for action – you win. Now what? 444

Nice moves 445

Time for action – the final bug 446

All done but for the shouting 446

C# addendum 447

Chapter 13: AI Programming and World Domination 449

Take it away, computer 449

Time for action – add computer control 450

Herpa derp derp 450

Unpacking the code 451

Time for action – code consolidation 452

Tic Tac Toe at the speed of light 456

Sore loser 456

Click-spamming for fun and profit 457

Artificial stupidity 457

Time for action – winning is everything 459

It's a trap! 460

The leftovers 462

Time for action – pseu pseu pseudocode 463

Time for action – begin at the end 464

Time for action – the final four 466

Code one, get one free 467

The actual intelligence behind artificial intelligence 468

Table of Contents

[ xi ]

Time for action – score! 469

Shut your trap 473

Detecting the tri-corner trap 476

Time for action – to catch a competitor 476

Perfection Horrible, horrible perfection. 480

Time for action – programming fallibility 480

Turning it up to "Smart" 482

Code encore 482

Summary 490

More hospitality 490

C# addendum 490

Chapter 14: Action! 501

Open heart surgery 501

Time for action – haul in the hallway 502

Time for action – meet me at camera two 504

Time for action – adjust Main Camera 506

Time for action – deck the halls 507

Time for action – turn on the lights 508

Time for action – set up the camera rig 517

Time for action – animate the bouncer 519

Time for action – I like to move it move it 521

Time for action – animate the runner 524

Time for action – how to "handle" Nurse Slipperfoot 526

Time for action – you spin me right round 528

Time for action – deploy your game 530

Time to grow 532

Beyond the book 533

Appendix 535

Index 539

Скачать