How do I add a component to an object during runtime.

Hello,
I am trying to figure this out but have not been able to find the answer anywhere.
I am trying to instantiate an object but it gets instantiated without any of the scripts attached to it.
How do I add a script component to an object when it gets instantiated?
Thanks!

AddComponent

You need to use the GameObject.AddComponent function. So if the instantiated Game Object is referenced to variable gameObj, then your line would look something like this: gameObj.AddComponent<SomeComponent> ();. Just change SomeComponent to the name of your component.

If you want to do with no monobehaviours, use System.Activator, if not, you will have to add it with the gameObject.AddComponent , or (System.Type),
If you want to get the type with the name, use System.Type.GetType (string name), or
Types.GetType (string name, string assembly (for C # use, Assembly-CSharp))