If you don’t use Debug.Log() you should! It will print anything you want into Unity’s console window while running the game in the Editor.

Warnings and Error

The Debug class also lets you write warnings and errors to the Console. This lets you give yourself valuable feedback when debugging.

Here’s what the different log types look like in the Console window:

Debug .Log, Debug.LogError, and Debug.LogWarning

Debug.LogError("This is a debug error message");
Debug.LogWarning("This is a debug warning message");

Pause the Game

Call Debug.Break() to pause your game in the Editor, allowing you to freeze the action at a particular point and look what’s happening:

Debug.Break();

Lines

Debug.DrawLine and Debug.DrawRay

The Debug class also lets you draw lines inside the Scene view while your game is playing. This is invaluable for working with linecasts and raycasts as it lets you see exactly what is happening in your scene, taking out the guesswork.

Debug lines are especially useful for making sure your vector maths is correct.

Debug.DrawLine() takes a start point, an end point, and a colour and draws a line (only visible in the Scene window while the game is running):