this vs gameobject

Hey everyone,

I was wondering what’s the difference between “this” and “gameobject” is. For example:

Destroy(gameObject); // This seems to be the correct way of destroying the current object

Destroy(this); // this doesn't seem to work

Just hoping to get some clarification and any help will be appreciated!

hello @Tycellent
The keyword “this” is a reference to the current class, where as gameObject is what object the script is on, when you call Destroy(this) you are just removing the script from the game object rather than trying to destroy the actual object.

this refers to the monobehaviour.

gameobject refers to the gameobject. (with all other behaviours and components)

Destroying ‘this’ means removing the script from the object.