How do I access the object the script is attached to?

This one has to be simple, but I can’t find the words to Google this.

I have a script attached to an object in Unity. From that script, how do I access the object’s name or other properties? I’ve read this page, but it doesn’t seem to address my question.

I’ve tried Gameobject.name and this.name, but I can’t make them work.

You attatch the script to the object then use the inspector tab in unity. You can also edit the name of the object in inspector.[12233-screen+shot+2013-06-20+at+11.01.36+pm.png|12233]

Oh my God, I needed a ‘==’ instead of a single ‘=’. What a rookie mistake. Thank you, everyone. You’re always so helpful.

according to your code here, you are accessing the name of the gameObject that you attach this script to, not to another gameObject

this wouldn’t really work in a collision situation as you want to find out what your current gameObject collided with, it cannot collide with itself.

you may want to look up triggers too

ive found this a good method for finding WHAT you have collided with.

    void OnTriggerEnter(Collider other) {
        if(other.gameObject.name == "RightFeeler")
        {
        Debug.Log("Right Feeler collided");
        Destroy(other.gameObject); //or whatever
        }
    }