🎮 Unity C# Basics: Debug.Log() Explained


🕹️ My First “Oh No” Moment in Unity
When I first opened Unity, I thought I would be making a game in five minutes.
Spoiler alert: I was wrong😒
I slapped a cube into the scene, hit play… and Unity immediately hit me back with errors😢. Bright red, scary looking errors. I had no idea what went wrong. I felt like I broke the whole engine.
That is when I met my first real friend in Unity: 👉 Debug.Log()
It is like Unity whispering back to you, “Hey, I heard you. Here’s what is happening.”
💡 What is Debug.Log()?
Think of it as sending yourself text messages but inside Unity. Every time you call Debug.Log(), a message pops up in the Console window. You can log words, numbers, or even values from your code.
It is the quickest way to ask, “Yo, did my code actually run?”
📝 A Simple Example
using UnityEngine;
public class HelloWorld : MonoBehaviour
{
void Start()
{
Debug.Log("🎉 The game started! Hello, Unity!");
}
}
What happens:
Attach this script to any object in your scene (yes, even a random cube).
Hit Play.
Check the Console.
Boom 💥you will see your message waiting for you.
It is the programmer’s equivalent of a “check engine” light.
🤔 Why You’ll Use It (All The Time)
To see if your script is actually running.
To check the value of a variable (like health, score, or player speed).
To trace what happens in your game when you press a button.
And honestly? Sometimes just to scream at your own code:
Debug.Log("WHY IS THIS STILL BROKEN?! 😭");
⚠️ A Friendly Warning
Debug.Log() is fun and useful, but don’t turn your game into a spam factory. Flooding the Console with hundreds of messages slows things down and clutters your view.
Pro tip:
Use Debug.LogWarning() for yellow “hmm, maybe fix this later” notes.
Use Debug.LogError() for red “yikes, fix this NOW” alerts.
🚀 Wrapping Up
And that is it. your first tool in the Unity toolbox. Debug.Log() is small, simple, and ridiculously helpful. Trust me, you will be leaning on it a LOT as you learn.
Next up in this series:
👉 Unity C# Basics: MonoBehaviour Guide (aka the mysterious thing that makes all Unity scripts actually work)
Thanks for hanging out and remember: if you’re lost, just log it😉
Subscribe to my newsletter
Read articles from Ques-tly directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
