Chapter 2. Introducing the Building Blocks for Unity Scripts

A programming language such as C# can appear to be very complicated at first but in reality, there are two parts that form its foundation. These parts are variables and methods. Therefore, understanding these critical parts is a prerequisite for learning any of the other features of C#. Being as critical as they are, they are very simple concepts to understand. Using these variable and method foundation pieces, we'll be introduced to the C# building blocks used to create Unity scripts.

For those people who get sweaty palms just thinking of the word script, wipe your hands and relax. In this chapter, I'm going to use terms that are already familiar to you to introduce the building blocks of programming. The following are the concepts introduced in this chapter:

  • Using variables in a script
  • Using methods in a script
  • The class which is a container for variables and methods
  • Turning a script into a Component
  • Components communicating using the Dot Syntax

Let's have a look at these primary concepts.

Using the term method instead of function

You are constantly going to see the words function and method used everywhere as you learn Unity.

Note

The words function and method truly mean the same thing in Unity. They do the same thing.

Since you are studying C#, and C# is an Object-Oriented Programming (OOP) language, I will use the word "method" throughout this book, just to be consistent with C# guidelines. It makes sense to learn the correct terminology for C#. Also, UnityScript and Boo are OOP languages. The authors of the Scripting Reference probably should have used the word method instead of function in all documentation.

Note

From now on I'm going to use the words method or methods in this book. When I refer to the functions shown in the Scripting Reference, I'm going to use the word method instead, just to be consistent throughout this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.37.136