#Whats the difference between Destroy(gameObject) and Destroy(this.transform.gameObject)?
From my understanding the second is just a long way to say the same thing. âthisâ refers to the script that is currently running, â.transformâ refers to the transform component where the script is located and then â.gameObjectâ refers to the object that the transform component is attached to. You shouldnât need the transform property since youâre jumping to it to jump away, instead this.gameObject should be enough.
Taking it a step further the code infers âthisâ if it doesnât know which property youâre talking about so it can be dropped all together and instead only gameObject is needed so youâre now left with Destroy(gameObject).
Itâs kind of like saying to somebody âHey I want you to eat from the fruitBowl, purple, Spanish, Grenache, fruit, grapesâ instead you could just say âEat the grapesâ thereâs no need to talk about the other details.
The important bit to remember is that you canât just use âthisâ ie Destroy(this) as it refers to the instance of the script not the gameObject itself or with the previous example eating me instead of the fruit.
Thank you for answer.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.