system
1
Hello,
I need to be able to use a xVar by declaring it from a String.
ie
This is pseudo-code
var xVar = 100;
var zVar = "xVar"
function X (){
callTheNameOfVarFromZvar.String = 200
}
in the example, xVar would go from 100 to 200, using as name the String in zVar.
I'm not sure if I make much sense, but I'll edit if I find a better way to explain...
Thank you.
Mike_3
2
You can do this with reflection (See System.Runtime.Reflection in the MSDN docs), but honestly I would skip it for now and use a Dictionary or a HashTable
In both cases, you'd use the string "zVar" to set and get the variable, e.g:
var dictionary = new Dictionary.<String, int>();
dictionary["zVar"] = 200;
Debug.Log(dictionary["zVar"]); //prints out 200
You'll need import System.Collections.Generic; at the top of your file for it to work