Game Development Reference
In-Depth Information
6. Insert a semicolon at the end.
and a debugging suggestion to insert a semicolon at the end of this line of code.
If you double-click the error message on the bottom, MonoDevelop will open with the cursor at the
location of the error. Test this by opening one of your scripts, deleting a semicolon from a line of
code, and saving the script; then close MonoDevelop. Now try to playtest, and watch the compiler
error messages appear in the Console tab of the Project panel and in the Scene view. Fix the error
by reinserting the semicolon, and save your script.
An error on one line of code can cascade to make subsequent lines of code also appear to have
errors. Once the first bug is fixed, these other pseudo-bugs will also disappear now that the compiler
can read subsequent lines of code correctly. For this reason, when debugging you want to start with
the first error that appears and methodically work your way through resolving the bugs in order.
Warnings
Whereas the compiler error in the previous example had a red stop sign icon to indicate the scene
cannot be played until the error is fixed, a warning uses a yellow yield-sign icon to catch your
attention regarding a problem, but also indicates the scene will still play (Figure 10-18 ).
Figure 10-18. Warning message displayed in the Console
Examples of warnings include notification of an unused variable, or a Unity function that will be
deprecated (obsolete) in upcoming versions.
You can create your own warnings with Debug.LogWarning . It works much like Debug.Log but
displays the warning icon in addition to the message and object context. To try this out, in the Unity
editor Project panel, open the Assets ➤ Scripts folder and find the ImpactForce script. Open it in
MonoDevelop and add the following line of code to the Start() function:
Debug.LogWarning("Warning!", this);
Save the script, playtest, and see your new warning appear in the Console (Figure 10-19 ).
Figure 10-19. Debug.LogWarning message displayed in the Console
 
Search WWH ::




Custom Search