There is a API reference that contains AddComponent, but it seems to have been made obselete (and it throws compiler error). No updated link has been found in the manual. Any other link found points to these forums, and are at most recent from 2016. Is there a new way to do it?
I think only the string version is obsolete. Don't use gameObject.AddComponent("MyScript"); Use gameObject.AddComponent<MyScript>(); // returns the created script
Oh yeah, AddComponent adds to the object you call it on, so gameObject will get the new component added to it. You couldn't then add it to some other object, so if you are making a new object you want to place a script on, it would look like this Code (csharp): GameObject someObName = new GameObject("I have a name!"); MyScript ms = someObName.AddComponent<MyScript>(); ms.someInt = 256; // ... etc