Game Development Reference
In-Depth Information
Figure 5-31. Commenting out the message code in the Start function
Be sure you haven't commented out the closing curly bracket for the Start function.
You will often see an alternate way to print to the console. Instead of using Debug,Log() , you can use
print() . Let's use it for the next test.
1.
Select each of the three objects with the script, and set their Ear Length
parameter to different values.
2.
Add a few blank lines above the commented section, and then add the
following to re-assign the value of the earLength variable:
earLength = earLength + 2.0f; // add to the value and re-assign it
print (earlength);
Once the variable has been declared in the script, you only refer to it by its name. For the value, a
float, you still must add the f . When assigning a value, the item receiving the value is always on the
left, the value is on the right, and the assignment operator, =, is used.
3.
Save the script, and click Play.
The amounts you set in the inspector have each been incremented by 2 at startup (Figure 5-32 ). So
the order of evaluation is initialized and the variable is overwritten by value set in Inspector, which in
turn is overwritten by the value assigned in the Start function. Note that during Play mode, the new
values can be seen in the Inspector.
 
Search WWH ::




Custom Search