- Home /
Parseing Varible names from strings
So, I'm trying to make a universal level save system, that you just drag and drop into a scene. For the most part it works, but it was suggested that I open it up to a bit of customization and allow for expansion and custom elements to be saved...
My question is, how can I, when reading the save file, read a string then find a variable on a class by that name? Heres some pseudo-code of what I hoped would work, but didn't (as I despairingly expected...):
int Count=0;
string[] sSplit = (xmlValue[Count]).Split(":" [0]);
(GameObject.GetComponent<(Split[0])>()).(sSplit[1]) = float.Parse(sSplit[2]);
xmlValue is assigned earlier as a similar split delineated using commas, but my question isn't about xml reading and writing, I know how to do that, its about that last line:
Can I feed GetComponent<>() a string like I am?
Can I then say Componenet.(String) like I am to access a variable? (I assume not)
If not, then how?
Answer by DaveA · Apr 12, 2012 at 11:45 PM
Can-o-worms I believe, but you should read into the MSDN under Reflection: http://msdn.microsoft.com/en-us/library/cxz4wk15(v=vs.95).aspx
Your answer
Follow this Question
Related Questions
Iterating through multidimensional arrays 2 Answers
iOS Not Converting String to Integer 0 Answers
C# - parsed strings not changing in function 1 Answer
XML parsing c# in unity 1 Answer