Any way to retrieve the *real* name of a script component?

According to the Unity API, Component.name always returns the name of the game object the component is attached to, not the actual component name. But what if I want the actual component name, such as the name of a script component, which – unlike things like Transform or Rigidbody – usually has a name that Unity won’t automatically recognize? Is there anyway I get the name of the script that makes up the component?

Thanks.

Debug.Log(this.GetType().ToString());

Note, that this will only work if “this” is not null. You can of course also put in a reference from outside of the script.

PlayerSpawner m_Spawner;
// get spawner somehow
print(m_Spawner.GetType().ToString());

Why do you need this? If you want to retrieve a class name without having a runtime instance of the class, it gets a lot more complicated. I found a solid solution on the web, but it’s far from trivial to create runtime instance by only using the string name of the class.