Need navagent to move towards a given element in an array. Please help.

A Game Controller scrip handles the population of the targets array. targets is populated with a sphere prefab.

I have a CubeMove script attached to a cube prefab, that is a navmeshagent that I want to simply move to the position of the element in the array. Here is the GameController script:
public class GameController : MonoBehaviour
{
public GameObject target; // this is a prefab that I load from a prefab folder in the inspector view.
public GameObject[] targets;
public GameObject cube; // prefab to instantiate

void Start()
{
SpawnTargets();
cube = Instantiate(cube, new Vector3(6f, 0.5f, 2f), Quaternion.identity); // instantiate cube here
}
void Update()
{
}
void SpawnTargets()
{
targets = new GameObject[4];
for (int i = 0; i < 4; i++)
{
targets = Instantiate(target, new Vector3(-6f, 0.5f, i * -4f), Quaternion.identity);
}
}
}
I then reference the targets[] array from within the CubeMove script and set the agents destination to the [0] element of the array:
public class CubeMove : MonoBehaviour
{
public GameObject targets; // GameController object is dragged in here to get reference.
UnityEngine.AI.NavMeshAgent agent;
GameController script;

void Start()
{
script = targets.GetComponent();
agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
}
void Update()
{
agent.destination = script.targets[0].transform.position;
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag(“target”))
{
other.gameObject.SetActive(false);
}
}
}
Currently though, when I hit run, the cube simply travels to the same position every single time (-6.46, 0.5833333, -6.14), it does not go towards the position of targets[0].
If anyone can point me in the right direction here that would be greatly appreciated.
Thanks for reading.

I believe this is an issue of assignment of prefabs. Firstly, from what i see in the CubeMove script you say that you drag in the targets gameobject. That way i must assume its an object that you dragged from the prefabs folder and not from the scene since prefabs cant have references to scene object. So, in order to fix that i believe you must add a line at the start function of your CubeMove script that grabs the instance of the targets object from the scene like so:

 void Start()
 {
     targets = GameObject.FindObjectOfType<GameController>().gameObject;
     script = targets.GetComponent<GameController>();
     agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
 }