Using Breakpoints to Halt Code Execution

There are times when you’re going to want to closely examine the code during runtime and Debug() won’t cut it. In these situations, we can attach MonoDevelop directly to the Unity process and step through code execution by using breakpoints.

Breakpoints cause the code to halt when they’re encountered. You can then use MonoDevelop to step through the code, one line at a time, to see where it goes and what it does. You can also monitor the values of variables while doing this, making it an excellent way to catch and resolve unexpected behaviors in your game.

We’re going to introduce one such behavior into our game and then use the debugger to catch it. Start by altering the PlayerController script to match ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.