Instead of storing the names of the classes, you can just store the list of components:
Include this line at the top of your script
using System.Collections.Generic;
Somewhere inside the class
List componentsToAdd; // Your list of components
void Start() {
componentsToAdd = new List();
componentsToAdd.add(/* some component */); // Repeat as necessary
}
When you want to add components
foreach (Component c in componentsToAdd) {
someGameObject.AddComponent(c.GetType());
}
↧