Where you declare a variable is important

You will be declaring and using variables in many places in a script. The variables that I have shown you so far are called member variables. They are members of the LearningScript class—not declared within any method. These member variables are the only variables that have the option of being displayed in the Inspector panel or being accessed by other scripts.

Note

Declaring your member variables at the beginning of a class may give you a mental clue that these member variables can be used anywhere in the script.

We will also be creating variables in methods. These variables are called local variables. They are never displayed in the Unity's Inspector panel, nor can they be accessed by other scripts. This brings us to another concept of programming, called variable scope.

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

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