[SOLVED] Understanding difference between "this" and "gameObject"

Hi everyone,
I’m having a hard time understanding the difference between “this” and “gameObject” in the Brick script, what do they refer to? I feel like we are using them to talk about the same thing but in the Destroy() method “this” is not working while when I try to get the Brick tag I can use either gameObject.tag or this.tag… So what’s the difference? Why Destroy(this) isn’t working??

As a reminder:

void OnCollisionEnter2D(Collision2D col) {
    bool isBreakable = (this.tag == "Breakable");
    if (isBreakable == true) {
        HandleHits();
    }
}
void HandleHits() {
    this.timesHit++;
    if (timesHit >= hitSprites.Length + 1) {
        Destroy(gameObject);
    }else {
        LoadSprites();
    }
}

I’ve read other posts about the same confusion, sorry about not doing a search before posting but now I don’t know how to delete this post so I flag it solved… :confused:

You can read my post in which I explain in detail what purpose the this keyword serves in C#:

Privacy & Terms