Debugging your code
While we're working through practical examples, we'll need a way to print out information and feedback to the Console window in the Unity editor. The programmatic term for this is debugging, and both C# and Unity provide helper methods to make this process easier for developers. You already debugged your code from the last chapter, but we didn't go into much detail about how it actually works. Let's fix that.
Whenever I ask you to debug or print something out, use one of the following methods:
- For simple text or individual variables, use the standard
Debug.Log()
method. The text needs to be inside a set of parentheses, and variables can be used directly with no added characters; for example:Debug.Log("Text goes here."); Debug.Log(CurrentAge);
This will produce the following in the Console panel:
Figure 3.1: Observing Debug.Log output
- For more complex debugging, use...