How to use proximity detector to detect objects coming closer using C# script

I want to detect if something is coming closer and I want to get its distance and name.

I won’t post the explicit code, but this is how you could do it:

  1. Have a sphere/box whatever trigger, that trigger would detect objects in a certain radius of your object.

  2. Have a list/array/dictionary of the GameObjects in that trigger.

  3. Whenever a new object enters the trigger, add it to that list.

  4. Have a dictionary that stores the distance from the previous frame from the player.

  5. Compare the 2 distances.