Learning C# by Developing Games with Unity 2019

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Harrison Ferrone
Series: Learning C# by Developing Games with Unity
Edition: 4
Publisher: Pakt
Year: 2019

Language: English
Pages: 532

Title Page......Page 2
Copyright and Credits......Page 4
Learning C# by Developing Games with Unity 2019 Fourth Edition......Page 5
Dedication......Page 7
About Packt......Page 8
Why subscribe?......Page 9
Packt.com......Page 10
Contributors......Page 11
About the author......Page 12
About the reviewer......Page 13
Packt is searching for authors like you......Page 14
Preface......Page 27
Who this book is for......Page 28
What this book covers......Page 29
To get the most out of this book......Page 32
Downloading the Example Code Files......Page 33
Downloading the Color Images......Page 34
Conventions Used......Page 35
Sections......Page 36
Time for Action......Page 37
What just happened?......Page 38
Pop Quiz – Heading......Page 39
Hero's Trial – Heading......Page 40
Get in Touch......Page 41
Reviews......Page 42
Section 1: Programming Foundations and C#......Page 43
Getting to Know your Environment......Page 44
Some basic prerequisites......Page 45
Starting out with Unity 2019......Page 46
Creating a new project......Page 48
Navigating the editor......Page 49
Using C# with Unity ......Page 51
Working with C# scripts......Page 52
Time for action – creating a C# script......Page 53
Introducing the Visual Studio editor......Page 54
Time for action – opening a C# file......Page 55
Beware of naming mismatches......Page 56
Syncing C# files......Page 57
Fixing a broken sync......Page 58
Documentation......Page 59
Accessing Unity's documentation......Page 60
Time for action – opening the Reference Manual......Page 61
Time for action – using the Scripting Reference......Page 63
Locating C# resources......Page 64
Time for action – looking up a C# class......Page 65
Pop quiz – dealing with scripts......Page 67
Summary......Page 68
The Building Blocks of Programming......Page 69
Defining variables......Page 70
Names are important......Page 71
Variables act as placeholders......Page 72
Time for action – creating a variable......Page 73
Time for action – changing a variable's value......Page 75
A method to the madness......Page 76
Methods drive actions......Page 77
Methods are placeholders too......Page 78
Time for action – a simple method......Page 79
Introducing classes......Page 81
A class all along......Page 82
Everyday blueprints......Page 83
Commenting is key......Page 85
Practical backslashes......Page 86
Time for action – adding comments......Page 87
Putting it together in Unity......Page 88
Scripts become components......Page 89
Variables and the Inspector panel......Page 90
A helping hand from MonoBehavior......Page 92
Hero's trial – MonoBehavior in the Scripting API......Page 93
Class and component communication......Page 94
Enter dot notation......Page 95
Pop quiz – C# building blocks......Page 96
Summary......Page 97
Diving into Variables,Types, and Methods......Page 98
Writing proper C#......Page 99
Simple debugging......Page 101
Variable syntax ......Page 102
Type and value declarations......Page 103
Type-only declarations......Page 104
Access modifiers......Page 105
Choosing a security level......Page 106
Time for action – making a variable private......Page 107
Working with types......Page 108
Common built-in types......Page 109
Time for action – playing with different types......Page 110
Time for action – creating interpolated strings......Page 111
Type conversions......Page 112
Inferred declarations......Page 113
Custom types......Page 114
Types roundup......Page 115
Naming variables......Page 116
Best practices......Page 117
Variable scope......Page 118
Introducing operators......Page 120
Arithmetic and assignments......Page 121
Time for action – executing incorrect type operations......Page 123
Pop quiz #1 – variables and types......Page 124
Defining methods......Page 125
Basic syntax......Page 126
Modifiers and parameters......Page 127
Time for action – defining a simple method......Page 128
Naming conventions......Page 129
Methods are logic detours......Page 130
Specifying parameters......Page 131
Assigning arguments......Page 132
Time for action – adding method parameters......Page 133
Specifying return values......Page 134
Time for action – adding a return type......Page 135
Using return values......Page 136
Time for action – capturing return values ......Page 137
Hero's trial – methods as arguments......Page 139
Common Unity methods......Page 140
The Start method......Page 141
The Update method......Page 142
Pop quiz #2 – Understanding methods......Page 143
Summary......Page 144
Control Flow and Collection Types......Page 145
Selection statements......Page 146
The if-else statement......Page 147
Basic Syntax......Page 148
Time for action – thieving prospects......Page 150
Using the NOT operator......Page 152
Nesting statements......Page 154
Evaluating multiple conditions......Page 155
Time for action – reaching the treasure......Page 156
The switch statement......Page 158
Basic syntax......Page 159
Pattern matching......Page 160
Time for action – choosing an action......Page 161
Fall-through cases......Page 163
Time for action – rolling the dice......Page 164
Pop quiz #1 – If, and, or but......Page 166
Collections at a glance......Page 167
Arrays......Page 168
Basic syntax......Page 169
Indexing and subscripts......Page 170
Range exceptions......Page 171
Lists......Page 172
Basic syntax......Page 173
Time for action – party members......Page 174
Common methods......Page 175
Dictionaries ......Page 176
Basic syntax......Page 177
Time for action – setting up an inventory......Page 178
Working with dictionary Pairs......Page 179
Pop quiz #2 – all about collections......Page 181
Iteration statements......Page 182
For loops......Page 183
Time for action – finding an element......Page 185
Foreach loops......Page 187
Looping through key-value pairs......Page 189
Hero's trial – finding affordable items......Page 190
While loops......Page 191
Time for action – tracking player lives......Page 192
To infinity and beyond......Page 194
Summary......Page 195
Working with Classes, Structs, and OOP......Page 196
Defining a class ......Page 197
Basic syntax......Page 198
Time for action – creating a character class......Page 199
Instantiating class objects......Page 200
Time for action – creating a new character......Page 201
Adding class fields......Page 202
Time for action – fleshing out character details......Page 203
Using constructors......Page 205
Time for action – specifying starting properties......Page 206
Declaring class methods......Page 208
Time for action – printing out character data......Page 209
What's a struct?......Page 211
Basic syntax......Page 212
Time for action – creating a weapon struct......Page 213
Classes vs structs......Page 215
Reference types......Page 216
Time for action – creating a new hero......Page 217
Value types......Page 219
Time for action – copying weapons......Page 220
The Object-Oriented mindset......Page 222
Encapsulation......Page 223
Time for action – adding a reset......Page 224
Inheritance......Page 225
Base constructors......Page 226
Time for action – calling a base constructor......Page 227
Composition......Page 229
Polymorphism......Page 230
Time for action – functional variations......Page 231
OOP roundup......Page 233
Applying OOP in Unity......Page 234
Objects are a class act......Page 235
Accessing components......Page 237
Basic syntax......Page 238
Time for action – accessing the current transform component......Page 239
Finding GameObjects......Page 241
Time for action - finding components on different objects......Page 242
Drag and drop......Page 244
Time for action – assigning variables in Unity......Page 245
Pop quiz: all things OOP......Page 246
Summary......Page 247
Section 2: Scripting Game Mechanics in Unity......Page 248
Getting Your Hands Dirty with Unity......Page 249
A game design primer......Page 250
Game design documents......Page 251
The Hero Born one-page......Page 252
Building a level......Page 253
Creating primitives......Page 254
Time for action – creating a ground plane......Page 255
Thinking in 3D......Page 256
Materials......Page 258
Time for action – changing the ground color......Page 259
White-boxing......Page 261
Editor tools......Page 262
Hero's Trial – putting up drywall......Page 264
Keeping the Hierarchy clean......Page 265
Time for action – using empty objects......Page 266
Working with prefabs......Page 268
Time for action – creating a turret......Page 269
Time for action – updating the prefab......Page 270
Time for action – finishing the level......Page 271
Hero's trial – creating a health pickup......Page 272
Lighting basics......Page 273
Creating lights......Page 274
Light component properties......Page 275
Animating in Unity......Page 276
Creating clips......Page 277
Time for action – creating a new clip......Page 278
Recording keyframes......Page 280
Time for action – spinning animation......Page 281
Curves and tangents......Page 283
Time for action – smoothing the spin......Page 285
The particle system......Page 286
Time for action – adding sparkle effects......Page 287
Pop quiz – basic Unity features......Page 289
Summary......Page 290
Movement, Camera Controls, and Collisions......Page 291
Moving the player......Page 292
Player setup......Page 293
Time for action – creating the player capsule......Page 294
Understanding vectors......Page 296
Getting player input......Page 298
Time for action – player locomotion......Page 300
Camera follow......Page 303
Time for action – Scripting camera behavior......Page 304
Working with Unity physics......Page 307
Rigidbodies in motion......Page 310
Time for action – accessing the Rigidbody......Page 311
Time for action – moving the Rigidbody......Page 313
Colliders and collisions......Page 315
Time for action – picking up an item......Page 317
Using Collider triggers......Page 320
Time for action – creating an enemy......Page 321
Time for action  – capturing trigger events......Page 322
Hero's trial – all the prefabs!......Page 325
Physics roundup......Page 326
Pop quiz – player controls and physics......Page 327
Summary......Page 328
Scripting Game Mechanics......Page 329
Adding jumps......Page 330
Enter enumerations ......Page 331
Underlying types......Page 332
Time for action – pressing the spacebar to jump!......Page 334
Working with layer masks......Page 336
Time for action – setting object layers......Page 337
Time for action – one jump at a time......Page 339
Shooting projectiles......Page 343
Instantiating objects......Page 344
Time for action – creating a projectile prefab......Page 345
Time for action – adding the shooting mechanic......Page 347
Managing GameObject buildup......Page 349
Time for action – destroying bullets......Page 350
The game manager......Page 352
Tracking player properties......Page 353
Time for action – creating a game manager......Page 354
The Get and Set properties......Page 356
Time for action – adding backing variables......Page 358
Time for action – updating item collection......Page 360
Player Polish......Page 362
Graphical User Interfaces......Page 363
Time for action – adding UI elements......Page 364
Win and Loss Conditions......Page 367
Time for action – winning the game ......Page 368
Using directives and namespaces......Page 370
Time for action – pausing and restarting ......Page 371
Pop quiz – working with mechanics......Page 373
Summary......Page 374
Basic AI and Enemy Behavior......Page 375
Navigating in Unity......Page 376
Navigation components......Page 377
Time for action – setting up the NavMesh......Page 378
Time for action – setting up enemy agents......Page 380
Moving enemy agents......Page 383
Procedural programming......Page 384
Time for action – referencing the patrol locations ......Page 385
Time for action – moving the enemy......Page 388
Time for action – patrolling continuously between locations......Page 390
Enemy game mechanics......Page 393
Seek and destroy......Page 394
Time for action – changing the agent's destination......Page 395
Time for action – lowering player health......Page 397
Time for action – detecting bullet collisions......Page 399
Time for action – updating the game manager......Page 402
Refactoring and keeping it DRY......Page 404
Time for action – creating a restart method......Page 405
Hero's trial – refactoring win/lose logic......Page 407
Pop quiz – AI and navigation......Page 408
Summary......Page 409
Section 3: Leveling Up Your C# Code......Page 410
Revisiting Types, Methods, and Classes......Page 411
Access Modifier redux......Page 412
Constant and read-only properties......Page 413
Using the static keyword ......Page 414
Time for action – creating a static class......Page 415
Methods Redux......Page 417
Overloading methods......Page 418
Time for action – overloading the level restart......Page 419
Ref parameters......Page 421
Time for action – tracking player restarts......Page 422
Out parameters......Page 424
OOP redux......Page 425
Interfaces......Page 426
Time for action – creating a manager interface......Page 427
Time for action – adopting an interface......Page 428
Abstract classes......Page 430
Class extensions......Page 432
Time for action – extending the string class......Page 433
Time for action – using an extension method......Page 435
Namespace Redux......Page 437
Type aliasing......Page 438
Pop quiz – leveling up......Page 439
Summary......Page 440
Exploring Generics, Delegates, and Beyond......Page 441
Introducing generics......Page 442
Generic objects......Page 443
Time for action – creating a generic collection......Page 444
Generic methods......Page 446
Time for action – adding a generic item......Page 447
Constraining type parameters......Page 449
Time for action – limiting generic elements......Page 450
Delegating actions......Page 451
Basic syntax......Page 452
Time for action – creating a debug delegate......Page 453
Delegates as parameter types......Page 455
Time for action – using a delegate argument......Page 456
Firing events......Page 458
Basic syntax......Page 459
Time for action – creating an event......Page 460
Handling event subscriptions......Page 462
Time for action – subscribing to an event......Page 463
Handling exceptions......Page 465
Throwing exceptions......Page 466
Time for action – checking negative scene indexes......Page 467
Using a try-catch......Page 469
Time for action – catching restart errors......Page 470
Design pattern primer......Page 473
Common game patterns......Page 474
Pop quiz – intermediate C#......Page 475
Summary......Page 476
The Journey Continues......Page 477
Scratching the surface......Page 478
Putting the pieces together......Page 479
Remembering your OOP......Page 480
Approaching Unity projects......Page 481
Unity features we didn't cover......Page 482
Next steps......Page 483
C# resources......Page 484
Unity resources......Page 485
Unity certifications......Page 486
Hero's trial – putting something out into the world......Page 487
Summary......Page 488
Completed Game Files......Page 489
Bullet behavior......Page 490
Camera behavior......Page 491
Enemy behavior......Page 492
Game behavior......Page 494
Item behavior......Page 497
Player behavior......Page 498
Supplementary Classes......Page 500
Custom extensions......Page 501
IManager......Page 502
Inventory list......Page 503
Utilities......Page 504
Pop Quiz Answers......Page 505
Chapter 1 – Getting to Know Your Environment......Page 506
Pop quiz – dealing with scripts......Page 507
Chapter 2 – Introducing the Building Blocks of Programming......Page 508
Pop quiz – C# building blocks......Page 509
Chapter 3 – Diving into Variables, Types, and Methods......Page 510
Pop quiz #1 – variables and types......Page 511
Pop quiz #2 – understanding methods......Page 512
Chapter 4 – Using Collections and Controlling Your Code......Page 513
Pop quiz #1 – If, and, or but......Page 514
Pop quiz #2 – all about collections......Page 515
Chapter 5 – Working with Classes, Structs, and OOP......Page 516
Pop quiz – all things OOP......Page 517
Chapter 6 – Getting Your Hands Dirty with Unity......Page 518
Pop quiz – basic Unity features......Page 519
Chapter 7 – Movement, Camera Controls, and Collisions......Page 520
Pop quiz – player controls and physics......Page 521
Chapter 8 – Scripting Game Mechanics......Page 522
Pop quiz – working with mechanics......Page 523
Chapter 9 – Basic AI and Enemy Behavior......Page 524
Pop quiz – AI and navigation......Page 525
Chapter 10 – Revisiting Types, Methods, and Classes......Page 526
Pop quiz – leveling up ......Page 527
Chapter 11 – Exploring Generics, Delegates, and Beyond......Page 528
Pop quiz – intermediate C#......Page 529
Other Books You May Enjoy......Page 530
Leave a review - let other readers know what you think......Page 532