Game Development Reference
In-Depth Information
To start debugging with MonoDevelop, let's consider breakpoints. When debugging
code, you'll likely need to observe the program flow when it reaches a specified line.
A breakpoint lets you mark one or more lines in a source file from MonoDevelop, and
when the program runs in Unity, its execution will pause at the first breakpoint. At
this pause, you get the opportunity to examine the code and the status of variables as
well as to inspect and edit their values. You can also continue execution with stepping.
This lets you push execution forward to the next line, following the normal program
logic line-by-line. You get the opportunity of inspecting your code in each line as it
passes. Let's see an example case. The following code sample 2-9 shows a simple script
file. When attached to an object, it retrieves a list of all objects in the scene (including
itself) and then sets their position to the world origin (0, 0, 0) when the Start function is
executed, which occurs at level startup:
using UnityEngine;
using System.Collections;
public class DebugTest : MonoBehaviour
{
// Use this for initialization
void Start ()
{
//Get all game objects in scene
Transform[] Objs = Object.FindObjectsOfType<Transform>();
//Cycle through all objects
for(int i=0; i<Objs.Length; i++)
{
//Set object to world origin
Objs[i].position = Vector3.zero;
}
}
}
Let's set a breakpoint in the highlighted line via MonoDevelop. This will pause the
program execution whenever it reaches this line. To set the breakpoint, position
your mouse cursor on the highlighted line, right-click on the left-hand gray margin,
and choose New Breakpoint . Otherwise, use the MonoDevelop application menu to
choose the New Breakpoint option in Run , or you can also press the F9 key (or you
can left-click on the line number), as shown here:
 
Search WWH ::




Custom Search