In Unity, I have two arrays, one of strings:
var options = new string[] { "north", "east", "south", "west" };
and another of JSON objects named room
, which I've setup per the MULTIPLE DATA(ARRAY JSON) solution given here. I won't list it here cos it's massive, but basically I can call room[1].north
and get some text back successfully.
I want to add many more things to the options array, so I'm trying to write a foreach loop that will iterate over everything in the options array and perform the same methods on each, i.e.
foreach (string option in options) {
GameObject optionObject = GameObject.Find (option);
TextMesh optionTextMesh = optionObject.GetComponent<TextMesh> ();
optionTextMesh.text = room[1].{some way to pass in "option" as the key};
}
Is it possible to interpolate a key on an object like this?