If statement without bool

private void DestroyPickup()
            if (GetPickup())

Question on this piece of code. GetPickup returns the Pickup type, not a bool. How does that work with an if statement? I’m guessing it returns true if it isn’t null and false if it is?

That’s exactly correct.
It’s important to note that this only works with components (MonoBehaviours) and ScriptableObjects. If you have a custom class that isn’t derived from either of these (or a built-in component like Animator), the compiler won’t let you use this construction.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms