Hi. This is my firs post of the forum and my English is not perfect. So, if i do something wrong, sorry already now.
I have arrays in my project and i want to access one of them with a string. For example;
//I have this arrays.
public string[] ARGENTINAcities;
public string[] BRAZILcities;
public string[] PERUcities;
public string[] MEXICOcities;
//I have a Text.
public Text cityname;
public void countryclick()
{
//When i click the button, i get its name as a string with "countryname".
//Like this, i click the "ARGENTINA" button and "countryname" becomes "ARGENTINA".
string countryname = EventSystem.current.currentSelectedGameObject.name;
//arrayname is that what i want to use to access arrays.
//Like this, arrayname = ARGENTINAcities;
arrayname = countryname + "cities";
//And here, i want to use "arrayname" as an array name to access its elements.
//Like this, cityname.text = arrayname[2];
}
I highly recommend you look into using JSON and loading that instead. That way if you add cities or countries, you do not need to recompile your program code.
Another way of organizing it is to place each array of city names into a ScriptableObject, which also gets you away from changing code every time you change data.