Game Development Reference
In-Depth Information
ToString
Many classes and objects in Unity have a ToString function (see line
16 of code sample 1-7). This function converts the object, such as an
integer (whole number), to a human-readable word or statement that
can be printed to the Console or Debugging window. This is useful
for printing objects and data to the console when debugging. Note that
converting numerical objects to strings requires an implicit conversion.
The following are the comments for code sample 1-7:
• Line 13 begins the while loop with the condition that it repeats until the
integer variable NumberOfMessages exceeds or equals 5
• The code block between lines 15 and 19 is repeated as the body of the
while loop
• Line 19 increments the variable NumberOfMessages on each iteration
The result of code sample 1-7, when executed in the game mode, will be to print
five text messages to the Unity Console when the level begins, as shown in the
following screenshot:
Printing messages to Console in a while loop
More information on the while loop and its usage in C# can be found at
http://msdn.microsoft.com/en-gb/library/2aeyhxcd.aspx .
 
Search WWH ::




Custom Search