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

Defining variables

Let's start off with a simple question: what is a variable? Depending on your point of view, there are a few different ways of answering that question, as follows:

  • Conceptually, a variable is the most basic unit of programming, such as an atom. Everything starts with variables, and programs can't exist without them.
  • Technically, a variable is a tiny section of your computer's memory that holds an assigned value. Every variable keeps track of where its information is stored (this is called a memory address), its value, and its type (for instance, numbers, words, or lists).
  • Practically, a variable is a container. You can create new ones at will, fill them with stuff, move them around, and reference them as needed. They can even be empty and still be useful:

A useful real-life example of a variable is a mailbox...