get name of child object script is attached to?

Hi, I'm trying to find the name of the current object that a script is attached to. I've got a hierarchy and a set of scripts, and I'm trying to use one script to send information to another game object. I've got all that working, but where I'm failing is where I'm trying to send the name of the current object that the script is attached to on with the SendMessage.

I've tried using "" but it gives me the parent of the hierarchy... like in this example:


I've got my script attached to C, D and E, all sending different values, but when I use "", it sends the name of "A" whereas I'd like to send [C,D or E] -- is there a way to do this without specifying the name of each one as a variable?

thanks in advance, Greg

You can use:

To get the name of the GameObject to which the current instance of the script is attached. That should give you the "C", "D", or "E" for each instance of the script which is attached to those particular GameObjects.

Remember, 'this' represents the instance of the script itself, not the GameObject, however Monobehaviours have a 'gameObject' property, which you can use as shown above.