Hi guys, I’ve got an interesting problem. I am trying to access static variables in a script of level data, but I want that script to have a unique name for each level:
level1
level2
level3
…
I can add these components to my field generator object no problem with:
var levelNum : int = level;
levelTemp = gameObject.AddComponent ("level" + levelNum);
The problem is, I need to call them as their Type for the iPhone to recognize them, like this other script for example:
FieldScript = scriptMaster.GetComponent(FieldArray) as FieldArray;
Unfortunately, I can’t use a string for the Type tag, so how do I get the component name dynamically? For example, if I need to load the level3 script, I want to do something like:
var levelNum : int = 3;
levelTemp = gameObject.AddComponent ("level" + levelNum);
levelScript = gameObject.GetComponent("level" + levelNum) as ("level" + levelNum);
Do you see my problem? I’ve tried many things, but I can’t seem to get that Type name using a string. Do I have to use System.Reflection for this? I understand that’s bad practice.
Any help would be appreciated, or if you’ve got a better idea of how to get the data from individual scripts, I’d love to hear it!
Thank you!