- Home /
This question was
closed Aug 17, 2014 at 08:43 PM by
GimLee for the following reason:
Seems impossible
How to declare the type after a string?
I need to do something like this:
private string stringValue = "SheepController"; //SheepController is the name of another script
private **stringValue** animal1;
So it would be like writing:
private SheepController animal1;
Is this even possible? Because it will differ from each level in my game, what script I would like to add to a gameobject.
Comment
Best Answer
Answer by robertbu · Aug 17, 2014 at 06:26 AM
Not sure of your game, but one common way is to declare a base class with a common interface and then derive the other classes from it. There are other solutions. Here is one question that talks about the issue:
http://answers.unity3d.com/questions/381529/how-to-address-scripts-without-knowing-their-names.html