Game Development Reference
In-Depth Information
Figure 2-21. Additional error warning in Console panel after Play attempt with error present
Big red warnings are ugly, so go ahead and fix the code, then save.
Variables and Functions
A computer only does what you tell it to do. It uses variables to hold data, and follows the
instructions for manipulating or processing the data you give it in the form of functions.
Change your code to look like this:
#pragma strict
// declare the variable myVar of type integer and give it a value of 8.
var myVar : int = 8;
function Start () {
Debug.Log(myVar);
}
First, take a closer look at the second line. Adding the double forward slash // at the beginning of a
line makes it a comment, indicated in MonoDevelop by a gray-colored font. Comments are used for
notes to yourself or other developers, such as describing the purpose of the subsequent block of
code. Code that seems perfectly clear when you are working on it may not be to someone else, or it
may become a lot fuzzier to you when you review it days, weeks, or much later. Do yourself and your
teammates a favor by building a good habit of commenting on your code as you go.
Note Commenting out code is useful during debugging. You can disable it by commenting instead of
deleting it, then easily re-enable it as needed.
For multiple lines put /* at the beginning and */ at the end of the comments or code. Try this by
commenting out the Start() function.
#pragma strict
// declare the variable myVar of type integer and give it a value of 8.
var myVar : int = 8;
 
 
Search WWH ::




Custom Search