Answer the question
In order to leave comments, you need to log in
Why is there no error in assignment to type bool Collider2D?
Why is there no error in assignment to type bool Collider2D? Why does the unit not throw errors, because the OverlapCircle method returns Collider2D?
bool isGrounded = Physics2D.OverlapCircle(groundcheck.position, radius, layerMask)
Answer the question
In order to leave comments, you need to log in
Because Collider2D inherits from Object, which has a bool conversion operator . Almost all unit entities can not be compared with null, but simply inserted into a condition, for example, if(transform)
. The appearance of this operator is connected with the fact that objects live not only in the sharp code, but also in the plus part of the engine. That is, in a sharp object may not be null, but in the positive part it has already been destroyed, and vice versa. But this was relevant a couple of years ago, since then they have rewritten the backend and I have not seen problems with this for a long time, consider that these are just the remains of legacy code. Still sometimes they ask about it at interviews, but this is rather rubbish knowledge, the design is so-so.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question