How do I assign a script to an instantiated prefab?

I am currently creating a “spell” particle effect prefab which I need to turn into a Rigidbody to control it’s physics to launch it through the use of an external script, the script itself is ready and setup but I am not sure how to assign that script to the said instantiated prefab.

Current code to spawn object:

GameObject go1;
spellFired = spellMechanics.testSpell1;
go1=Instantiate(spellFired,spellSpawn1.position, spellSpawn1.rotation) as  GameObject;	
go1.transform.parent=transform;

Just simple code I did to test out some different things, how would I go about assigning a script that is in my project folders (does it have to be within the Scene existing somewhere?)

Thanks in advance. Cheers.

Maybe you can try GameObject.AddComponent.

ScriptClass myScript = gameObject.AddComponent<ScriptClass>();

You can use the GameObject.AddComponent - function.

The script doesn’t have to be anywhere in the scene, if it is included in your Unity project, the compiler will find it.

–jaakaappi