Applying Scripts held in a list to a game object
Hello all, This may be the simplest thing in the world but, I currently have a list containing a series of scripts that the user has plugged in at the front end of my program, just like you can do with game objects only applied to MonoScripts now I am looking to take these scripts and apply them to the GameObject the script is attached to, somthing along the line of
gameObject.AddComponent<DetectionUnits[0].name>;
were "DetectUnits" is:
public List<DetectMod> DetectionUnits;
Received from a script higher up the chain any tips ?
Answer by LucianoMacaDonati · Nov 13, 2016 at 06:16 AM
I think we might need some more information or for you to show code for our better understanding. But if I understood you correctly, what you're trying to do sounds a lot like polymorphism. All the scripts that the user has available inherit from a base class, and you call a method (maybe an abstract method that everyone implements) that the selected child(s) run dynamically. Sounds good ? Let me know.
Your answer
Follow this Question
Related Questions
How to rotate an object 2 Answers
How to change Rigidbody interpolate through script. 0 Answers
Adding in script. Look at details. 0 Answers
How to make object spawn only once? 1 Answer
Instantiate after loading scene 0 Answers