Game Development Reference
In-Depth Information
Compilation errors and the console
Debugging typically refers to error-busting techniques for runtime use; that is, it
refers to the things you can do to find and correct errors when your game is running.
This understanding of debugging, of course, presupposes that your code is already
valid and compiled. The implicit assumption is that you can write valid statements
in C# and compile code, and you just want to find runtime errors that occur as a
result of program logic. Thus, the focus is not on syntax but on logic, and this is
indeed true. However, in this section, I'll speak very briefly about code compilation,
about writing valid code, and using the console to find and correct errors of validity.
This is important, both to introduce the Console window generally and also to
establish a firm basis of thinking about debugging in more depth. Consider the
following code sample 2-1 script file ( ErrorScript.cs ):
01 using UnityEngine;
02 using System.Collections;
03
04 public class ErrorScript : MonoBehaviour
05 {
06 int MyNumber = 5;
07
08 // Use this for initialization
09 void Start () {
10
11 mynumber = 7;
12 }
13
14 // Update is called once per frame
15 void Update () {
16 mynumber = 10;
17 }
18 }
To compile the preceding code sample 2-1, simply save the script file in
MonoDevelop ( Ctrl + S ) and then refocus the Unity Editor window. From here,
compilation will happen automatically. If it doesn't, you can also right-click on
the script file from the Project panel and choose Reimport from the context menu.
For the code sample 2-1, two errors are generated, and these will be shown in the
Console window. If you don't already have the Console window open, it could be
shown by selecting the Console option from Window from the application menu.
The Console window is highly important, and you'll almost always want it open
somewhere in the interface. This is where Unity as an engine communicates with
you as a developer. Thus, if your code has compile errors, Unity would list them
to Console , letting you know what they are.
 
Search WWH ::




Custom Search