Adding existing script at run-time and changing it's properties


I am adding an existing scripts at run-time.
Different camera effects scripts.
I want to access their properties and set values in code, like fade, Contrast (Some scripts has additional properties).

To add the script to the camera is use the following method:

System.Type MyScriptType = System.Type.GetType(StringOfMyEffectScript + ",Assembly-CSharp");
Component effectInstance = Camera.main.gameObject.AddComponent(MyScriptType);

In design time Unity does not know which properties exists since script is not loaded yet.
How do i set script properties at run-time ?

You can only use AddComponent to add MonoBehaviour to an object.

So if your script is called

Weapon for example, it MUST inherit from MonoBehaviour in order to be able to use AddComponent, you also don’t require to get the type.

public class Weapon : MonoBehaviour { public string Name; }

var weaponScript = Camera.main.gameObject.AddComponent<Weapon>();

weaponScript.Name = "blabla";

On a side note, it might be better to already have the scripts on the objects.
And instead simply disabled them and when you need to enabled them.
AddComponent is an expensive call.