I'm confused about "this"

I thought that “this” refers to the instance of the script rather than the object it is attached to, and that you used “gameObject” if you wanted to reference the object. Why in this video does “this.GetComponent<>()” work then if “this” is referring to the script instance?

I’m still really confused about this. Can anyone help?

It is just another way to call the method, “this” indeed refers to the instance of the script and GetComponent is indeed of the class GameObject, but there are some shortcuts that allow us to write things implicitly, you can call GetComponent right away without anything before it for example, and it will still know that it is the component of the GameObject that has the script attached.

Okay. Thanks!

Privacy & Terms