When I want to add a new script to a GameObject I do:

var newGO = new GameObject("new name");
var thisInstance = newGO.AddComponent(MyScriptName);

But if MyScriptName has public/exposed parameters (the ones that appear in the Inspector window), how can I tell AddComponent their values?

Thanks

Usually I have to set the variables manually:

var newGO = new GameObject("new name");
var thisInstance = newGO.AddComponent(MyScriptName);

thisInstance.somePubVar = myValue;

If you have a ton of variables to set, it’s probably better off to setup a public function that you pass all the values to. This is great for many reasons; You won’t forget how many varibles need to be set because the prototype will remind you. And you can setup tests in the function to see if the values make sense.

Also, it let’s you set private values.