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:
-
Have a sphere/box whatever trigger, that trigger would detect objects in a certain radius of your object.
-
Have a list/array/dictionary of the GameObjects in that trigger.
-
Whenever a new object enters the trigger, add it to that list.
-
Have a dictionary that stores the distance from the previous frame from the player.
-
Compare the 2 distances.