Using GetComponent to access array index in second script

I’m trying to build a class whose one and only purpose in life is to populate string arrays with line-delimited textassets when the program begins, so other classes can ping it later and ask for specific indexes of the array.

Currently, in the class I use to parse my textassets, I have a line:

public TextAsset txtLastNames;
	public void Awake(){
	string[] lastNamesArray = txtLastNames.text.Split("

"[0]);
}

After using the inspector to assign txtLastName to the textasset I want, in a script attached to the player I try to access a random index in the array to give my guy a random name, as so:

private NPCGenerator _npcGenerator;

void Start () {
	_npcGenerator = GameObject.Find("GameMaster").GetComponent<NPCGenerator>();
	GenerateCharacter ();
}

Now, what I want to do is access my array in the GenerateCharacter() function:

private void GenerateCharacter(){

characterLastName = _npcGenerator.lastNamesArray [Random.Range(0f,10f)];

}

This produces an error, " Type NPCGenerator' does not contain a definition for lastNamesArray’ and no extension method lastNamesArray' of type NPCGenerator’ could be found’, and when I type it out I can’t get ‘lastNamesArray’ to pop up on the autocomplete. Experimentation demonstrates that I can only get this to work with public variables, but changing my string declaration to public string yields an error, “Unexpected symbol ‘public’”. Is my problem syntactic, or am I plain approaching the problem in the wrong way?

I’m not sure how exactly you are declaring public but have you tried declaring it outside of the method, like so:

public TextAsset txtLastNames;
public string[] lastNamesArray;
public void Awake(){
    lastNamesArray = txtLastNames.text.Split('

');
}