- Home /
Question by
benfattino · Jul 11, 2015 at 04:51 PM ·
variablestaticname
Call static variable dynamically
Is it possibile call a static var with variable name? For example call Manager.Var_ + "i"?
void PopulateList () {
foreach (var item in itemList) {
i = 1;
GameObject newButton = Instantiate (sampleButton) as GameObject;
SampleButton button = newButton.GetComponent <SampleButton> ();
button.nameLabel.text = item.name;
button.icon.sprite = item.icon;
button.button.onClick = item.thingToDo;
button.tag = item.tag;
Manager.var_ + "i" = item.var; ->> Here i need function similar to this!!!!
newButton.transform.SetParent (contentPanel);
i++;
}
}
Comment
Best Answer
Answer by NoseKills · Jul 11, 2015 at 07:25 PM
It is possible but very inefficient and needlessly complicated.
Instead you should make`Manager.var_` an array and assign values into the array
Manager.varsArray[i] = item.var;
Your answer
Follow this Question
Related Questions
Global Variables Refuse to Cooperate 1 Answer
Variable access simulateneously 3 Answers
I´ve got a problem with my Coin System. It always shows 1 Coin. 2 Answers
Be able to choose which variable I want from another scripts public variable 2 Answers
Is there any way to edit variables inside other scripts without declaring them as static? 1 Answer