Output with Debug.Log
- Game Development course
- Beginner
- Lesson 29/83
- 4 min
Learn to print to the console with Debug.Log and watch values.
Debug.Log and the Console Window
In Unity, Debug.Log is used to verify code execution and monitor variables while the game runs. All messages sent via Debug.Log are printed to the Console window of the Unity editor. This method is the developer's most crucial tool for testing mechanics and diagnosing bugs.
Debug.Log("Oyun basariyla baslatildi!");Double-clicking a message in the Console window jumps directly to the line of code that triggered it.
Warnings and Error Messages
You can send not only informational messages to the console, but also warnings and errors tailored to specific situations. Use Debug.LogWarning with a yellow icon for potential issues, and Debug.LogError with a red icon for critical failures. You can concatenate variable values using the + operator.
int can = 15;
Debug.Log("Kalan can: " + can);
Debug.LogWarning("Can degeri cok dustu!");Different log types can be filtered in the Console window, making problem detection straightforward.
Practice Print variable with Debug.Log
Inside the Main method, use Debug.Log to print the expression "Puan: " + score to the console.
Starter code
using System;
public static class Debug
{
public static void Log(object message) => Console.WriteLine(message);
}
public class Program
{
public static void Main()
{
int score = 50;
// Debug.Log ile yazdir
}
}Sample solution
using System;
public static class Debug
{
public static void Log(object message) => Console.WriteLine(message);
}
public class Program
{
public static void Main()
{
int score = 50;
Debug.Log("Puan: " + score);
}
}Expected output
Puan: 50
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 In which editor window are messages printed with Debug.Log() listed in Unity?
- Console Correct answer
- Hierarchy
- Inspector
- Project
Explanation: In Unity, Debug.Log, Debug.LogWarning, and Debug.LogError outputs are displayed in the Console window.
2 Printing info to console
Debug.____("Oyun basladi!");
Debug.Log("Oyun basladi!");
Explanation: In Unity, the Log method of the Debug class is used to write general informational messages to the console.
3 Log types and purposes
| Term | Meaning |
|---|---|
Debug.Log |
Prints a standard informational message |
Debug.LogWarning |
Prints a yellow warning message |
Debug.LogError |
Prints a red critical error message |
Console penceresi |
Where logs and compile errors are listed |