What is Unity Debug.Log()?
What is Unity Debug.Log()?
Hello friends, in this post I will talk to you about a small command that we commonly use in Unity.
Debug.Log is a structure that allows us to see some text in Unity's console section.
For example, when two objects collide or touch each other, we use Debug.Log to verify this and print to the console that the objects have collided.
Sample Unity console screenshot
Examples of Debug.Log() Usage
A Debug.Log that prints "Game Started" when the scene loads
void Start(){
Debug.Log("Game Started");
}
Displaying a randomly generated number in the console with Debug.Log
void Start(){
int randomNumber = Random.range(0,10);
Debug.Log("Generated number : "+ randomNumber);
}
Apart from these usages, Debug.Log has many uses, and these uses are up to you. For example, in a line of code you wrote with if and else, such as to know if the if or else branch is running, or to print the generated number as the number increases with a for loop, you can use it in many places. Even, you can print things like which object you touched with a collider.


Yorum Gönder