Detecting script atached to collider

Is there any way to detect if a script is added to a collider? Thank you.

Nobody?

Hi, my first guess would be:

var cmp : Component = aGameObject.GetComponent("ScriptName") as Component;
if (cmp == null)
   Debug.Log("ScriptName is not found on " + aGameObject.name);

Oooh awesome thank you!

And after I do that, lets say cmp is a script, how can I acces variables and functions inside it?

Technically a script can’t be attached to a collider, as both scripts and colliders are both components of GameObjects and cannot exist in the scene by themselves. So basically what you’re asking is, “How do you determine if a script is attached to the same GameObject as a collider”?

Then you would need to access the gameObject component of the object with the collider on it and use GetComponent, like Loran showed.

Let me give you an example. In my scene I have a block witch have 100hp. If a cube hits it, I wanna make this 100hp value lower by decreasing it with a value of a variable from a script atached to the hitting block. Thats it.

not good with unityscript, but its somethig like

var cmp : MyScript = aGameObject.GetComponent("MyScript") as MyScript;
if (cmp == null)
   Debug.Log("ScriptName is not found on " + aGameObject.name);
else
   cmp.hp -= 100;

Great thanks!!