Performance wise what would be better? Calculating distance every frame or only calculating it after a yield - yield WaitForSeconds(Random.Range(1,4));
I’m asking because a lot of this will be happening in game and I’m not sure how performance friendly distance calculations or yields are.
It will be faster to do it after a yield. Yield has relatively no overhead so its almost always ok to turn a regular function into a yield.
Distance…well distance isn’t a very expensive value to calculate, but like most math, the less you have to do it, the better so moving it to a yield won’t hurt.
Note: You might have to create a new WaitForSeconds object that would allocate memory. But running the coroutine itself is as cheap as calling it through Update()