Debugging with Debug.Log – custom messages
Perhaps, the oldest and most well-known debugging technique in Unity is to use Debug.Log
statements to print diagnostic messages to Console, thus illustrating program flow and object properties. This technique is versatile and appealing because it can be used in practically every Integrated Development Environment (IDE) and not just MonoDevelop. Further, all the Unity objects, including vector and color objects, have a convenient ToString
function that allows their internal members (such as X, Y, and Z) to be printed to a human-readable string—one that can be easily sent to the console for debugging purposes. For example, consider the following code sample 2-3. This code sample demonstrates an important debugging workflow, namely, printing a status message about an object at its instantiation. This script, when attached to a scene object, prints its world position to Console, along with a descriptive message:
01 using UnityEngine; 02 using System...