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();
}
}