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.

Pleas note that I don't want to use raycast

1 Answer

1

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.

Thanks, I understood what you said. But I am not following everything exactly.

But you got the main principle right?

Did you try the "strip engine code" option in the build settings? (Just a wild guess) https://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html