What is the difference between using Object.Destroy()
and GameObject.Destroy()
in Unity?
I found the following info about that: here and here, but it did not answer my question.
So, could someone explain the matter foolproof, please?
None. GameObject.Destroy()
is inherited from Object.Destroy()
. Both statements refer to the same method.
This is not explicitly clear in the official API documentation, but most programmers can assume that to be the case based on the fact that both GameObject
and Object
contain the method, and GameObject
inherits from Object
. It can then be confirmed through IDEs or through the unofficial decompied source-code by MattRix on GitHub (GameObject
's source code does not contain the Destroy()
method, meaning it can only come from inheritance).
As such, you will also find the Destroy()
method on anything else in the inheritance tree of Object
. For example, Component
also inherits from Object
, and so you can add a Destroy()
statement within any component's code, without explicitly including Object.
before it.
Note: My answer is independent, but some credits to Hellium for answering correctly first in the OP.
GameObject
, theDestroy
function is inherited from parent class (which isObject
) \$\endgroup\$