Ok, so if I cast a 2D ray and want to use the RaycastHit2D … for example, using the code below:
targetHit = Physics2D.Raycast (transform.position, new Vector2 (0, -1));
if (targetHit) {
Debug.Log ("Hit!”);
} else {
Debug.Log ("No hit");
}
I understand that the if condition could be (targetHit != null) and that is clear.
Why is it that the (targetHit) is read as “True” when it is not empty/null?
Is this analagous to other programming languages like Python where:
- A default zero integer is False, but any other number is True
- A default empty String is False, but any other string is True
… example … (in Python3)
if “test”:
print(“True”)
else:
print(“False”)