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!
Answer by JuanPabloEsteban · Jan 20, 2016 at 03:39 PM
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.
Answer by kellerr112 · Jan 20, 2016 at 03:21 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612060753im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Use 'this.gameObject' even if the gameobject is hidden 1 Answer
UI text not showing in my scrollView 0 Answers
Minesweeper - Surrounding Objects - C# 0 Answers
this.GetComponent() won't return gameObject? How to get it without using this.gameObject? 3 Answers
Find a specific object using transform 0 Answers