How to iterate through gameobject scripts?

I saw

for(var i:Transform in gameobj.transform)

but it doesn’t work with scripts as they have no transforms

Hi, As all scripts that you can attach to a gameobject inherit from Monobehaviour you can get a list of the attached scripts by doing:


scripts = gameObject.GetComponents<MonoBehaviour>();
for(int i = 0; i < scripts.Length; i++){
	MonoBehaviour data = scripts*;*
  • Debug.Log(data);*
    And this is untested but I think unityscript would be:
    var scripts : Component[] = gameObject.GetComponents(MonoBehaviour);
    for(var i : int = 0; i < scripts.length; i++){
    _ var data : MonoBehaviour = scripts*;_