How to get variables from other Scripts on trigger enter?

Hello,

in my project, I have a DialogManager. This Manager can handle a Dialog parsed by a XML-Reader. This works fine. But now, I have more than one dialog.
My idea (or my question): Get the name, or id of this NPC, if the player collides with them.

Process: Player collides with NPC A - press ‘E’ and a dialog (specified to NPC A) appears. The Player moves forward and collides with NPC B - press ‘E’ and a other(!) dialog appears.

Am I correct in this way?

Structure:

Player has a script ‘DialogManger.cs’
NPCs have a script ‘ShowName.cs’ - there is a variable ‘NPCName’ - this variable should be used for open different dialogs.

Thanks for reading.

Greetings,

V4mpy

You could get a hold of the name like this:

void OnTriggerEnter(Collider other) {
	string name = other.gameObject.GetComponent<ShowName>().NPCName;
}

If you make name global, e.g. declare it outside of the function, you could check which name is currently set when the ‘E’ key is pressed to show the proper dialogue.