Question by
Maniacbob · Nov 27, 2016 at 02:55 PM ·
instantiatelistaddcomponent
Add Script from a List to Instantiated GameObject
I've got a list of scripts inherited from a common parent class and I want to add one from the list onto a game object. I can add one of the scripts if I address it directly using gameObject.AddComponent<Script>()
but if I try to insert my list reference or some variable holding it I get error saying that the reference couldn't be found in the namespace. Also using .AddComponent("Script")
will again work for a direct reference but not using the list reference. I know that I could use an elaborate if/else or switch statement that could work but it sorta defeats the point of using a list at all and makes everything more complicated. Is there an easier and cleaner method to achieving the same end?
Comment