Add all scripts to gameObject from var

Hey All,

Is it possible to store all scripts from one object into a variable and then add those scripts to another object?

For example, something like:

var scriptList  : MonoBehaviour [] = GetComponents(MonoBehaviour);

 var otherObject = Instantiate(monster);
otherObject.AddComponent(MonoBehaviour) = scriptList;

I’ve been trying versions around this, but nothing has worked so far. I do not want to name a specific script. I just want to get whatever script is attached.

one way or another you would need to differentiate your own components from unity’s. the scripts you write are components just like the others. So I would make a list of scripts to look for so you are not coping over rigidbody and animators and stuff. Cause they are scripts too!

var tocopy:String = "MoveScript AIscript WhateverScript blah blah";
var comps:Component[];
var i :int;
		// get a list all of compents attached to this object
		i = comps.Length;
		while (i>0) {
			            print(comps *.GetType ().ToString ());*

// see if it is in our string before adding to the new object
_ if (tocopy.Contains (comps .GetType ().ToString ())) {_
_ otherObject.AddComponent (comps .GetType ().ToString ());_

* }*
* }*
alternatively you could Look for the term “unityengine” in the name of the component and filter it that way but i would reccomend the list approach to give you a bit more controll!!!