How do you load a script in a script? (9071)

I've been looking around and I can't find an answer. (Not that I looked every nook and cranny, but a little general search.)

Pretty much what I'm looking for is something like making a variable to hold a script, then calling it in an Update method.

I want this for modular-bility. Like on collide, it can sometimes explode or get vaporized.

Are you sure you wouldn't just want to call maybe a function from another script or variable instead of loading a whole script inside another one? I'm not even sure you can do what you are asking...

Yes, like attaching Vaporize and Explode scripts to your object. Then at run time, do collision.gameObject.GetComponent<Explode>() or collision.gameObject.GetComponent<Vaporize>() to access your scripts.

1 Answer

1

You can use AddComponent to add new components to a GameObject at runtime

http://unity3d.com/support/documentation/ScriptReference/GameObject.AddComponent.html