[Solved] Question about "this" keyword

Hello, everyone!

I have a question about the “this” keyword on this specific case. When we use it, it is referring to the “Paddle” script (if i understood it right), so how can we change the position of the actual Paddle GameObject by changing the “Paddle” script transform? Does a script even has a transform, or it acts like it has the same as the GameObject it is attached to? I’ve seen a similar question in this forum, but it didn’t really clarified me.

Thanks for the help, and sorry if you find grammar/syntax errors. Englando is not my main idiom

“this” literally means “this object” so if you are in a paddle script on the paddle and you wanted to look at the transform, if there wasn’t already the shortcut for it (which there is as you can literally just write transform) you could do this.transform.

I don’t think there are many places in Unity it can be useful, but yeah, if you need to access something on the current object you can use “this” to say “i want to look at the current object” :slight_smile:

1 Like

Thanks for the answer, i understand it better now. I just have one more question: if “this” means “this object” why does Destroy (this) only destroy the script and not the object?

because with Destroy you have to point it specifically at the object you want to destroy. just doing “this” will point it at the script, but if you wish you destroy the whole object, you need to do Destroy(this.gameObject) :slight_smile:

Oh i see. That’s a lot :smiley:

No problem, happy deving! :smiley:

1 Like

Privacy & Terms