Finding the closest gameobject of another gameobject

Generally speaking, your choices lie in three areas:

  • do less work (consider fewer entities)

  • do the work less often (does it need to be updated each frame or can it be calculated one unit per frame so you get updated once per 100 frames??)

  • come up with a different approach to achieve the same ends

Because the answers to the above are closely tied to your game’s needs, it’s kinda hard to answer specifically.

But remember, DO NOT OPTIMIZE CODE RANDOMLY… always start by using the profiler:

Window → Analysis → Profiler

Optimizing UnityEngine.UI setups:

1 Like