Learning C# by Developing Games with Unity 2021: Kickstart your C# programming and Unity journey by building 3D games from scratch, 6th Edition
- Length: 487 pages
- Edition: 6
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2021-11-09
- ISBN-10: 1801813949
- ISBN-13: 9781801813945
- Sales Rank: #338570 (See Top 100 Books)
Learn C# programming from scratch using Unity as a fun and accessible entry point with this updated edition of the bestselling series
Key Features
- Learn C# programming basics, terminology, and coding best practices
- Become confident with Unity fundamentals and features in line with Unity 2021
- Apply your C# knowledge in practice and build a working first-person shooter game prototype in Unity
Book Description
The Learning C# by Developing Games with Unity series has established itself as a popular choice for getting up to speed with C#, a powerful and versatile programming language with a wide array of applications in various domains. This bestselling franchise presents a clear path for learning C# programming from the ground up through the world of Unity game development.
This sixth edition has been updated to introduce modern C# features with Unity 2021, including the new Unity Input Manager and animating with code. A new chapter has also been added that covers reading and writing binary data from files, which will help you become proficient in handling errors and asynchronous operations.
The book acquaints you with the core concepts of programming in C#, including variables, classes, and object-oriented programming. You will explore the fundamentals of Unity game development including game design, lighting basics, player movement, camera controls, and collisions. You will write C# scripts for simple game mechanics, perform procedural programming, and add complexity to your games by introducing smart enemies and damage-causing projectiles.
By the end of the book, you will have developed the skills to become proficient in C# programming and built a playable game prototype with the Unity game engine.
What you will learn
- Follow simple steps and examples to create and implement C# scripts in Unity
- Develop a 3D mindset to build games that come to life
- Create basic game mechanics such as player controllers and shooting projectiles using C#
- Divide your code into pluggable building blocks using interfaces, abstract classes, and class extensions
- Become familiar with stacks, queues, exceptions, error handling, and other core C# concepts
- Learn how to handle text, XML, and JSON data to save and load your game data
- Explore the basics of AI for games and implement them to control enemy behavior
Who This Book Is For
If you’re a developer, programmer, hobbyist, or anyone who wants to get started with C# programming in a fun and engaging manner, this book is for you. Prospective Unity game developers will also find this title useful. No prior experience in programming or Unity required.
Table of Contents
- Getting to Know Your Environment
- The Building Blocks of Programming
- Diving into Variables, Types, and Methods
- Control Flow and Collection Types
- Working with Classes, Structs, and OOP
- Getting Your Hands Dirty with Unity
- Movement, Camera Controls, and Collisions
- Scripting Game Mechanics
- Basic AI and Enemy Behavior
- Revisiting Types, Methods, and Classes
- Introducing Stacks, Queues, and HashSets
- Saving, Loading, and Serializing Data
- Exploring Generics, Delegates, and Beyond
- The Journey Continues
Preface Who this book is for What this book covers To get the most out of this book Get in touch Getting to Know Your Environment Technical requirements Getting started with Unity 2021 Using macOS Creating a new project Navigating the editor Using C# with Unity Working with C# scripts Introducing the Visual Studio editor Opening a C# file Beware of naming mismatches Syncing C# files Exploring the documentation Accessing Unity's documentation Locating C# resources Summary Pop quiz – dealing with scripts The Building Blocks of Programming Defining variables Names are important Variables act as placeholders Understanding methods Methods drive actions Methods are placeholders too Introducing classes A common Unity class Classes are blueprints Communication among classes Working with comments Single-line comments Multi-line comments Adding comments Putting the building blocks together Scripts become components A helping hand from MonoBehaviour Hero's trial – MonoBehaviour in the Scripting API Summary Pop quiz – C# building blocks Diving into Variables, Types, and Methods Writing proper C# Debugging your code Understanding variables Declaring variables Type and value declarations Type-only declarations Using access modifiers Working with types Common built-in types Type conversions Inferred declarations Custom types Naming variables Understanding variable scope Introducing operators Arithmetic and assignments Defining methods Declaring methods Naming conventions Methods as logic detours Specifying parameters Specifying return values Using return values Hero's trial – methods as arguments Dissecting common Unity methods The Start method The Update method Summary Pop quiz – variables and methods Control Flow and Collection Types Selection statements The if-else statement Using the NOT operator Nesting statements Evaluating multiple conditions The switch statement Pattern matching Fall-through cases Pop quiz 1 – if, and, or but Collections at a glance Arrays Indexing and subscripts Range exceptions Lists Accessing and modifying lists Dictionaries Working with dictionary pairs Pop quiz 2 – all about collections Iteration statements for loops foreach loops Looping through key-value pairs while loops To infinity and beyond Summary Working with Classes, Structs, and OOP Introducing OOP Defining classes Instantiating class objects Adding class fields Using constructors Declaring class methods Declaring structs Understanding reference and value types Reference types Value types Integrating the object-oriented mindset Encapsulation Inheritance Base constructors Composition Polymorphism Applying OOP in Unity Objects are a class act Accessing components Accessing components in code Drag and drop Summary Pop quiz – all things OOP Getting Your Hands Dirty with Unity A game design primer Game design documents The Hero Born one-page Building a level Creating primitives Thinking in 3D Materials White-boxing Editor tools Hero's trial – putting up drywall Keeping the hierarchy clean Working with Prefabs Lighting basics Creating lights Light component properties Animating in Unity Creating animations in code Creating animations in the Unity Animation window Recording keyframes Curves and tangents Summary Pop quiz – basic Unity features Movement, Camera Controls, and Collisions Managing player movement Moving the player with the Transform component Understanding vectors Getting player input Moving the player Scripting camera behavior Working with the Unity physics system Rigidbody components in motion Colliders and collisions Picking up an item Using Collider triggers Creating an enemy Hero's trial – all the Prefabs! Physics roundup Summary Pop quiz – player controls and physics Scripting Game Mechanics Adding jumps Introducing enumerations Underlying types Working with layer masks Shooting projectiles Instantiating objects Adding the shooting mechanic Managing object build-up Creating a game manager Tracking player properties The get and set properties Updating item collection Creating a GUI Displaying player stats Win and loss conditions Pausing and restarting the game with using directives and namespaces Summary Pop quiz – working with mechanics Basic AI and Enemy Behavior Navigating 3D space in Unity Navigation components Setting up enemy agents Moving enemy agents Procedural programming Referencing the patrol locations Moving the enemy Enemy game mechanics Seek and destroy: changing the agent's destination Lowering player health Detecting bullet collisions Updating the game manager Refactoring and keeping it DRY Summary Pop quiz – AI and navigation Revisiting Types, Methods, and Classes Access modifiers Constant and read-only properties Using the static keyword Revisiting methods Overloading methods ref parameters out parameters Intermediate OOP Interfaces Abstract classes Class extensions Namespace conflicts and type aliasing Summary Pop quiz – leveling up Introducing Stacks, Queues, and HashSets Introducing stacks Popping and peeking Common methods Working with queues Adding, removing, and peeking Common methods Using HashSets Performing operations Intermediate collections roundup Summary Pop quiz – intermediate collections Saving, Loading, and Serializing Data Introducing data formats Breaking down XML Breaking down JSON Understanding the filesystem Working with asset paths Creating and deleting directories Creating, updating, and deleting files Working with streams Managing your Stream resources Using a StreamWriter and StreamReader Creating an XMLWriter Automatically closing streams Serializing data Serializing and deserializing XML Serializing and deserializing JSON Data roundup Summary Pop quiz – data management Exploring Generics, Delegates, and Beyond Introducing generics Generic objects Generic methods Constraint type parameters Adding generics to Unity objects Delegating actions Creating a debug delegate Delegates as parameter types Firing events Creating and invoking events Handling event subscriptions Cleaning up event subscriptions Handling exceptions Throwing exceptions Using try-catch Summary Pop quiz – intermediate C# The Journey Continues Diving deeper Remembering your object-oriented programming Design patterns primer 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
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Learning C# by Developing Games with Unity 2021: Kickstart your C# programming and Unity journey by building 3D games from scratch, 6th Edition
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.