How to reference object script is attached to?

How would I reference the object that a script it attached to? Would it just be “this”, or is there a different way to do it?

For example, say I have a camera follow script and I want to access the Camera’s position, how would I do so?

gameObject will refer to the GameObject the script is attached to.

Also see the “Inherited members” section in the documentation (1) for shortcuts to access other components/properties of gameObject.

The script is attached to a game object, so this.transform.position would be the position of the game object. You can even get the parent game object’s transform (if your script is on a game object that is a child of the camera for instance) this.transform.parent.transform

@ IronArrow

Yes, there is… just right click on a script and select Find References In Scene. This will display all GameObjects your script is attached to in that scene.
If your script is attached to a prefab that will be instantiate at runtime, you have to press play before trying to find the references ;).

print(gameObject.name) is a good way to find it out. What I’m looking for is to directly see what game object a script is attached to in some kind of “reverse lookup way”, i.e. If I go to the scripts folder and see all the scripts I would like to right click and have an option that says something like “Show all game objects this script is attached to”, is there a way other than adding print(gameObject.name); to the script?

Thanks