NPCs with "passing" Dialogue

Basically, I want to have it so that when the player character moves near/past an NPC they have a floating box above their head showing lines of dialogue that are different each time the player passes. What sorts of systems need to play together to get something like this working? I need a starting point as I don’t even know what to Google for something like this.

Add a trigger box to your NPC which covers the space around your NPC that you want to be the activation space. Then use the on overlap of the trigger to activate the NPC. Within your NPC set up an array with each of the dialogues as the elements then each time it is activated go to the next item in the array and play it.