AddComponent argument in quotes vs without

What is the difference between something like AddComponent(“Collider”) and AddComponent(Collider) - what do the quotes do exactly?

The “unquoted” version works for javascript too, and is easier than in C#: AddComponent(Collider). It’s better to use the unquoted version whenever you can: it’s faster, and the compiler checks if the type exists.

The string version should be used only when you need to select the type to add at runtime, or when the type doesn’t exist at compile time - this may happen when you want to add a script written in a different language, because C# and JS can’t see each other during compilation. If you want to add the script “PlayerStatus.cs” to an object in a JS script, for instance, you may write AddComponent(“PlayerStatus”) - AddComponent(PlayerStatus) will not work unless PlayerStatus has been previously compiled.

In JS, AddComponent("Collider") returns Component, whereas AddComponent(Collider) returns Collider, plus the non-string version runs faster, and if you make a typo, the compiler will catch it.

In C#, AddComponent("Collider") and AddComponent(typeof(Collider)) both return Component, though the non-string version still has the advantage of being faster and more typo-proof. In order to actually get Collider instead of Component, you can cast: AddComponent(typeof(Collider)) as Collider, or use the generic version, AddComponent<Collider>(), though the generic version is slightly slower.

You can use the generic version in JS, AddComponent.<Collider>(), which returns Collider, however there’s no point, since it does the same thing as the non-generic version, except it’s uglier and slightly slower.

The quotes are for passing in by the name (as a string) of the script instead of the by it’s type. According to the script reference, the second one (without quotes) is for C# users. They use the generic method:

AddComponent<Collider>();

JavaScript users use:

var c : Collider;
c = gameObject.AddComponent ("Collider");

Provided that you adhere the convention that the type is the same as the script name, then it shouldn’t matter which one you use if you are using JavaScript. Though I never code in Boo, it seems to support both. In my experience with C# only the generic method works.