Game Development Reference
In-Depth Information
Let's begin by seeing what happens when you print something to the console from the Update
function. The VariablesTest script is on three objects, so you would get everything in triplicate. Now
would be a good time to create a new script.
1.
Right-click over the Test Scripts folder in the Project view and, from Create,
select C# Script.
2.
Name it UpdateTests .
3.
Double-click on it to open it in the script editor.
The new script gets its own tab in the script editor (Figure 5-36 ).
Figure 5-36. The new script in the MonoDevelop editor
4.
Just below the class declaration, create the following variable:
int counter = 1;
Note that this variable is not public , so it will not appear in the Inspector.
5.
Inside the Update function's opening and closing curly brackets, add the
following:
counter++; // increment the counter by 1
print (counter);
Using ++ to increment a value by one is the most abbreviated way to get the job done (Figure 5-37 ).
You will see it used quite often.
 
Search WWH ::




Custom Search