Learning C# by developing games with Unity 2020 : an enjoyable and intuitive approach to getting started with C# programming and Unity
â Scribed by Harrison Ferrone
- Year
- 2020
- Tongue
- English
- Leaves
- 356
- Edition
- Fifth
- Category
- Library
No coin nor oath required. For personal study only.
⌠Table of Contents
Cover
Title Page
Copyright and Credits
Dedication
About Packt
Contributors
Table of Contents
Preface
Chapter 1: Getting to Know Your Environment
Technical requirements
Getting started with Unity 2020
Using macOSÂ
Creating a new project
Navigating the editor
Using C# with UnityÂ
Working with C# scripts
Introducing the Visual Studio editor
Time for action â opening a C# file
Beware of naming mismatches
Syncing C# files
Exploring the documentation
Accessing Unity's documentation
Time for action â opening the Reference Manual
Time for action â using the Scripting Reference
Locating C# resources
Time for action â looking up a C# class
Summary
Pop quiz â dealing with scripts
Chapter 2: The Building Blocks of Programming
Defining variables
Names are important
Variables act as placeholders
Time for action â creating a variable
Time for action â changing a variable's value
Understanding methods
Methods drive actions
Methods are placeholders too
Time for action â creating a simple method
Introducing classes
A common Unity class
Classes are blueprints
Working with comments
Practical backslashes
Multi-line comments
Time for action â adding comments
Putting the building blocks together
Scripts become components
A helping hand from MonoBehavior
Hero's trial â MonoBehavior in the Scripting API
Communication among classes
Summary
Pop quiz â C# building blocks
Chapter 3: Diving into Variables, Types, and Methods
Writing proper C#
Debugging your code
Declaring variables
Type and value declarations
Type-only declarations
Using access modifiers
Choosing a security level
Time for action â making a variable private
Working with types
Common built-in types
Time for action â playing with different types
Time for action â creating interpolated strings
Type conversions
Inferred declarations
Custom types
Types roundup
Naming variables
Best practices
Understanding variable scope
Introducing operators
Arithmetic and assignments
Time for action â executing incorrect type operations
Defining methods
Basic syntax
Modifiers and parameters
Time for action â defining a simple method
Naming conventions
Methods are logic detours
Specifying parameters
Time for action â adding method parameters
Specifying return values
Time for action â adding a return type
Using return values
Time for action â capturing return valuesÂ
Hero's trial â methods as arguments
Dissecting common Unity methods
The Start method
The Update method
Summary
Pop quiz â variables and methods
Chapter 4: Control Flow and Collection Types
Selection statements
The if-else statement
Basic syntax
Time for action â thieving prospects
Using the NOT operator
Nesting statements
Evaluating multiple conditions
Time for action â reaching the treasure
The switch statement
Basic syntax
Pattern matching
Time for action â choosing an action
Fall-through cases
Time for action â rolling the dice
Pop quiz 1Â â if, and, or but
Collections at a glance
Arrays
Basic syntax
Indexing and subscripts
Range exceptions
Lists
Basic syntax
Time for action â party members
Common methods
DictionariesÂ
Basic syntax
Time for action â setting up an inventory
Working with dictionary pairs
Pop quiz 2 â all about collections
Iteration statements
For loops
Time for action â finding an element
foreach loops
Looping through key-value pairs
Hero's trial â finding affordable items
while loops
Time for action â tracking player lives
To infinity and beyond
Summary
Chapter 5: Working with Classes, Structs, and OOP
Defining a classÂ
Basic syntax
Time for action â creating a character class
Instantiating class objects
Time for action â creating a new character
Adding class fields
Time for action â fleshing out character details
Using constructors
Time for action â specifying starting properties
Declaring class methods
Time for action â printing out character data
Declaring structs
Basic syntax
Time for action â creating a weapon struct
Understanding reference and value types
Reference types
Time for action â creating a new hero
Value types
Time for action â copying weapons
Integrating the object-oriented mindset
Encapsulation
Time for action â adding a reset
Inheritance
Base constructors
Time for action â calling a base constructor
Composition
Polymorphism
Time for action â functional variations
OOP roundup
Applying OOP in Unity
Objects are a class act
Accessing components
Basic syntax
Time for action â accessing the current transform component
Time for action â finding components on different objects
Drag and drop
Time for action â assigning variables in Unity
Summary
Pop quiz â all things OOP
Chapter 6: Getting Your Hands Dirty with Unity
A game design primer
Game design documents
The Hero Born one-page
Building a level
Creating primitives
Time for action â creating a ground plane
Thinking in 3D
Materials
Time for action â changing the ground color
White-boxing
Editor tools
Hero's trial â putting up drywall
Keeping the hierarchy clean
Time for action â using empty objects
Working with prefabs
Time for action â creating a turret
Time for action â updating the prefab
Time for action â finishing the level
Hero's trial â creating a health pickup
Lighting basics
Creating lights
Light component properties
Animating in Unity
Creating clips
Time for action â creating a new clip
Recording keyframes
Time for action â spinning animation
Curves and tangents
Time for action â smoothing the spin
The particle system
Time for action â adding sparkle effects
Summary
Pop quiz â basic Unity features
Chapter 7: Movement, Camera Controls, and Collisions
Moving the player
Player setup
Time for action â creating the player capsule
Understanding vectors
Getting player input
Time for action â player locomotion
Adding a following Camera
Time for action â scripting camera behavior
Working with Unity physics
Rigidbody components in motion
Time for action â accessing the Rigidbody component
Time for action â moving the Rigidbody component
Colliders and collisions
Time for action â picking up an item
Using Collider triggers
Time for action â creating an enemy
Time for action â capturing trigger events
Hero's trial â all the prefabs!
Physics roundup
Summary
Pop quiz â player controls and physics
Chapter 8: Scripting Game Mechanics
Adding jumps
Introducing enumerationsÂ
Underlying types
Time for action â pressing the spacebar to jump!
Working with layer masks
Time for action â setting object layers
Time for action â one jump at a time
Shooting projectiles
Instantiating objects
Time for action â creating a projectile prefab
Time for action â adding the shooting mechanic
Managing GameObject buildup
Time for action â destroying bullets
Creating a game manager
Tracking player properties
Time for action â creating a game manager
The get and set properties
Time for action â adding backing variables
Time for action â updating item collection
Adding player polish
Graphical UI
Time for action â adding UI elements
Win and loss conditions
Time for action â winning the gameÂ
Using directives and namespaces
Time for action â pausing and restartingÂ
Summary
Pop quiz â working with mechanics
Chapter 9: Basic AI and Enemy Behavior
Navigating in Unity
Navigation components
Time for action â setting up the NavMesh
Time for action â setting up enemy agents
Moving enemy agents
Procedural programming
Time for action â referencing the patrol locationsÂ
Time for action â moving the enemy
Time for action â patrolling continuously between locations
Enemy game mechanics
Seek and destroy
Time for action â changing the agent's destination
Time for action â lowering player health
Time for action â detecting bullet collisions
Time for action â updating the game manager
Refactoring and keeping it DRY
Time for action â creating a restart method
Hero's trial â refactoring win/lose logic
Summary
Pop quiz â AI and navigation
Chapter 10: Revisiting Types, Methods, and Classes
Access Modifier redux
Constant and read-only properties
Using the static keywordÂ
Time for action â creating a static class
Methods redux
Overloading methods
Time for action â overloading the level restart
Ref parameters
Time for action â tracking player restarts
Out parameters
OOP redux
Interfaces
Time for action â creating a manager interface
Time for action â adopting an interface
Abstract classes
Class extensions
Time for action â extending the string class
Time for action â using an extension method
Namespace redux
Type aliasing
Summary
Pop quiz â leveling up
Chapter 11: Introducing Stacks, Queues, and HashSets
Introducing stacks
Basic syntax
Time for action â storing collected items
Popping and peeking
Time for action â the last item collected
Common methods
Working with queues
Basic syntax
Adding, removing, and peeking
Common methods
Using HashSets
Basic syntax
Performing operations
Summary
Pop quiz â intermediate collections
Chapter 12: Exploring Generics, Delegates, and Beyond
Introducing generics
Generic objects
Time for action â creating a generic collection
Generic methods
Time for action â adding a generic item
Constraining type parameters
Time for action â limiting generic elements
Delegating actions
Basic syntax
Time for action â creating a debug delegate
Delegates as parameter types
Time for action â using a delegate argument
Firing events
Basic syntax
Time for action â creating an event
Handling event subscriptions
Time for action â subscribing to an event
Handling exceptions
Throwing exceptions
Time for action â checking negative scene indexes
Using try-catch
Time for action â catching restart errors
Design pattern primer
Common game patterns
Summary
Pop quiz â intermediate C#
Chapter 13: The Journey Continues
Scratching the surface
Remembering your object-oriented programming
Approaching Unity projects
Unity features we didn't cover
Next steps
C# resources
Unity resources
Unity certifications
Hero's trial â putting something out into the world
Summary
Pop Quiz Answers
Other Books You May Enjoy
Index
đ SIMILAR VOLUMES
<p><b>Learn C# programming from scratch using Unity as a fun and accessible entry point with this updated edition of the bestselling series</b></p><h4>Key Features</h4><ul><li>Learn C# programming basics, terminology, and coding best practices</li><li>Become confident with Unity fundamentals and fea