How do I make a GameObject chase the nearest spawned game object?

I want to spawn spheres and make a cube chases them. However, this cube is chasing them in the order that they spawn, not the closest ones. I want to make this cube chase the closest spheres, even if it has to change the direction before getting the sphere that it is currently chasing. Can someone please help me? Thank you.
P.S. They spawn more rapidly than the cube can destroy then and the function to destroy the spheres is in another code.
Transform _food;
CharacterController _controller;

float _speed = 5.0f;

void Start()


void Update()
    GameObject foodGameObject = GameObject.FindGameObjectWithTag("Food");
    _food = foodGameObject.transform;
    _controller = GetComponent<CharacterController>();
    Vector3 direction = _food.position - transform.position;
    _controller.Move(direction * Time.deltaTime * _speed);



Put your spawned spheres in a List and than Linq may help you like below:

YOURSPHERESLIST.Sort((x, y) =>  Vector3.Distance(x.transform.position, YOURCUBE.transform.position).CompareTo(Vector3.Distance(y.transform.position, YOURCUBE.transform.position)));

With this line of code your spheres will be sorted from nearest to furthest. So YOURSPHERESLIST[0] will be the closest one which you want to chase in this case. But i must warn you this cost too much performance. So i suggest you to sort your objects when a new one spawned not per frame. And try not even using Linq this much if you are dealing with mobile platform.

And one more suggestion try not to destroy your objects if you dont have to but store them somewhere and activate/deactivate them when you need to use them.

have you tried using the rigid body of the one chasing the spawned object?
you could do
rigidbody.Addforce(new vector 3(x,y,z));
or you could try making the one chasing the spawned object a child of it