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

Class and component communication

Up until now, we've described classes and by extension, Unity components, as separate standalone entities; in reality, they are deeply intertwined. In fact, you'd be hard pressed to create any kind of meaningful software application without invoking some kind of interaction or communication between classes.

Enter dot notation

If you remember the post office example from earlier, the example code made use of periods (or dots) to reference classes, variables, and methods. If you think of classes as directories of information, then dot notation is the indexing tool:

PostOffice.Address

Any variables, methods, or other data types within a class can be accessed with dot notation. This applies to nested, or subclass information as well, but we'll tackle all those subjects when we get to Chapter 5, Working with Classes and Object-Oriented Programming.

Dot notation is also what drives communication...