Book Image

Learning C# by Developing Games with Unity 2019 - Fourth Edition

By : Harrison Ferrone
Book Image

Learning C# by Developing Games with Unity 2019 - Fourth Edition

By: Harrison Ferrone

Overview of this book

Learning to program in today’s technical landscape can be a daunting task, especially when faced with the sheer number of languages you have to choose from. Luckily, Learning C# with Unity 2019 removes the guesswork and starts you off on the path to becoming a confident, and competent, programmer using game development with Unity. You’ll start off small by learning the building blocks of programming, from variables, methods, and conditional statements to classes and object-oriented systems. After you have the basics under your belt you’ll explore the Unity interface, creating C# scripts, and translating your newfound knowledge into simple game mechanics. Throughout this journey, you’ll get hands-on experience with programming best practices and macro-level topics such as manager classes and flexible application architecture. By the end of the book, you’ll be familiar with intermediate C# topics like generics, delegates, and events, setting you up to take on projects of your own.
Table of Contents (20 chapters)
Free Chapter
1
Section 1: Programming Foundations and C#
7
Section 2: Scripting Game Mechanics in Unity
12
Section 3: Leveling Up Your C# Code

What this book covers

Chapter 1, Getting to Know Your Environment, will get you started with the Unity installation process, the editor's main features, and finding documentation for both C# and Unity-specific topics. We'll also go through creating C# scripts from inside Unity and take a look at the Visual Studio application, where all our code editing will take place.

Chapter 2, The Building Blocks of Programming, begins by laying out the atomic-level concepts of programming, giving you an opportunity to relate variables, methods, and classes to situations in everyday life. From there we move on to simple debugging techniques, proper formatting and commenting, and take a look at how Unity turns C# scripts into components.

Chapter 3, Diving into Variables, Types, and Methods, takes a deeper look at variables. This includes C# data types, naming conventions, access modifiers, and everything else you'll need for the foundation of a program. We'll also go over how to write methods, incorporate parameters, and use return types effectively, ending with an overview of standard Unity methods belonging to the MonoBehaviour class.

Chapter 4, Control Flow and Collection Types, introduces the common approaches to making decisions in code, consisting of the if-else and switch statements. From there we move on to working with arrays, lists, and dictionaries, and incorporating iteration statements for looping through collection types. We end the chapter with a look at conditional looping statements and a special C# data type called enumerations.

Chapter 5, Working with Classes, Structs, and OOP, details our first contact with constructing and instantiating class and struct objects in code. We'll go through the basic steps of creating constructors, adding class or struct variables and methods, and the fundamentals of subclassing and inheritance. The chapter will end with a comprehensive explanation of object-oriented programming and how it applies to C#.

Chapter 6, Getting Your Hands Dirty with Unity, will mark our departure from C# syntax into the world of game design, level building, and Unity's featured tools. We'll start by going over the basics of a game design document, then move into blocking out our level geometry and adding lighting and a simple particle system.

Chapter 7, Movement, Camera Controls, and Collisions, will explain different approaches to moving a player object and setting up a third-person camera. We'll discuss incorporating Unity physics for more realistic locomotion effects, as well as how to work with collider components and capture interactions within a scene.

Chapter 8, Scripting Game Mechanics, will introduce the concept of game mechanics and how to effectively implement them. We'll start with a simple jump action, and create a shooting mechanic, and build off the last chapter's code by adding logic to handle item collection.

Chapter 9, Basic AI and Enemy Behavior, starts with a brief overview of artificial intelligence in games and the concepts we will be applying to Hero Born. Topics covered in this chapter will include navigation in Unity using the level geometry and a navigation mesh, smart agents, and automated enemy movement.

Chapter 10, Revisiting Types, Methods, and Classes, takes a more in-depth look at data types, intermediate method features, and additional behaviors that can be used for more complex classes. This chapter will give you a deeper understanding of the versatility and breadth of the C# language.

Chapter 11, Exploring Generics, Delegates, and Beyond, will detail some of the more intermediate features of the C# language and how to apply them in practical, real-world scenarios. We'll start with an overview of generic programming and progress to concepts such as delegation, events, and exception handling. The chapter will end with a brief discussion of common design patterns and set you up for further study.

Chapter 12, The Journey Continues, reviews the main topics you've learned throughout the book and leaves you with resources for further study in both C# and Unity. Included in these resources will be online reading material, certification information, and a host of my favorite video tutorial channels.

Appendix A, Completed Game Files, contains all the necessary C# scripts that make up Hero Born.

Appendix B, Supplementary Classes, contains the intermediate code from Chapters 10, Revisiting Types, Methods, and Classes and Chapter 11, Exploring Generics, Delegates, and Beyond, that don't have any direct impact on the game mechanics of Hero Born.

Appendix C, Pop Quiz Answers, contains the answers to each chapter quiz presented throughout the book.