- Home /
Can I use strings with static variables?
Hi there! I've been wondering, if I can make as script that lets me define a variable as in inspector, that is then fetched from other script.
I hope this example of nonfunctionin imaginary code shows what I am after:
var TargetVar = "pcount"; //This string here tells which Var to get.
if(StoredStaticVariablesScript.TargetVar<1){ //This here gets it, although I can see that it will never work like this
print("No More!");
}
I hope you got what I am looking for
Any ideas?
that's something I am trying to put the right wordings before making it as a question. I think the question is more about making dynamic linkage within the inspector, like being able to access public variable of a component within the inspector. It would be a lot more beneficial than simply put a string that relates ( perhaps) to something else, that would be not very good coding strategy and prone to errors I feel.
Answer by Eric5h5 · Jan 24, 2011 at 04:02 PM
You could use eval() for that, although there's a performance hit the first time it's used with a piece of code, since it has to be compiled on the fly.
Answer by Wahooney · Jan 24, 2011 at 11:26 AM
This may be possible if you made a custom editor for your first script, you'll need some kind of reference to the second script inside the first.
Your answer
Follow this Question
Related Questions
GetComponent from string name? 3 Answers
How does one inspect static vars? 3 Answers
Storing Static String into new String variable 2 Answers
Is it possible to show Static Variables in the Inspector? 10 Answers