- Home /
Script / Debug.log question
I want to know how to use Debug.log in If statement
and thats all :/ cause im trying to use console in If statement with Debug.log if u didnt understand i mean this
If (// what to put in here? i want to put debug.log (3) but it doesnt work) {
Destroy(this.gameobject);
}
What possible use could that have? Debug.Log() is a void method, meaning it will not return anything.
In order to use an if statement, a method must return either a boolean, float, double, or int value.
Example: if(TurnToNumber("1")) would be true, as 1 in an integer if check results as a true statement.
Example: if(TurnToNumber("0")) would be false, as 0 in an integer if check results as a false statement.
Example: if(GameIsOn()) would be a boolean value, true or false.
In order to use an if statement, a method must return either a boolean, float, double, or int value.
@tw1st3d, incorrect, an if statement is based off a boolean expression.
Go type if(1) Debug.Log(true) into a file and see what happens, buddy.
Go type if(1) Debug.Log(true) into a file and see what happens, buddy.
Aren't you sweet. In c# 1 can represent true and 0 false... this makes sense as it represent a boolean value(or a bit). However, stating:
In order to use an if statement, a method must return either a boolean, float, double, or int value.
Is 100% incorrect.
But interestingly enough, Boolean.TryParse will fail on conversion of "1", "0" and "-1", but thats converting a string.
And a screenshot:
And to use an if statement you don't have to use a method, you could just say if (1 < 0) which would be false, no method used.
Answer by Landern · Nov 26, 2014 at 06:01 PM
An if statement use evaluate to either true or false.
if (gameObject != null)
{
Debug.Log("The gameObject is NOT null");
}
else
{
Debug.Log("The gameObject IS null");
}
if (score > highscore)
{
Debug.Log("The current score is higher then the highscore... you win!");
}
else
{
Debug.Log("The current score is NOT higher then the highscore... you win!");
}
if (gameObject.Name == "Tommy")
{
Debug.Log("The gameObject.Name IS equal to \"Tommy\""); // escape characters to display double quotes in string instead of terminating it.
}
else
{
Debug.Log("The gameObject.Name IS NOT equal to \"Tommy\""); // escape characters to display double quotes in string instead of terminating it.
}
Debug.Log actually doesn't return anything, it returns void.. nadda.
Now if you want to evaluate something then use the debug.log to display something, that is different, but that's not what you asked.