How can i see if an object has a script attached to it?

I would like to get a script attached to my object, if there is one.
I know i can usually use GetComponent to do this, but in this case i don’t know what the script will be. It might be anything at all, so i can’t specify a class to get.

I know that limits what i can do with it, thats fine. I just want to know if there is a script, of any sort, attached.

Is this doable?

Check to see how many instances of MonoBehaviour you have on the Game Object like this:

MonoBehaviour[] components = GetComponents<MonoBehaviour>() as MonoBehaviour[];

Debug.Log("Contains " + components.Length + " Scripts");

if(components.Length > 0){
    Debug.Log("I have scripts attached!");

If you want to include Other Components as well, such as Rigidbodies, Colliders, etc, use Component instead of MonoBehaviour like this:

Component[] components = GetComponents<Component>() as Component[];

Debug.Log("Contains " + components.Length + " Components");

if(components.Length > 0){
    Debug.Log("I have Components attached!");

All scripts extend MonoBehaviour so you can do GetComponent < MonoBehaviour > () == null to check if there is any attached