Calling a function from another script.

I store my game objects in an array:

targetArray.Push(targetPrefab);

Now I randomly select one of the game objects from the array using:

targetArray[random(0,targetArray.length)];

How can I call a function that is on the game object in the script myScript?

You need to

var somInstance : SomeClass = targetArray[random(0,targetArray.length)].GetComponent(SomeClass);
someInstance.SomeFunction();

or a better approach would be to store the instances you need in an array (preferably a builtin array ) and then just call the function

var targetArray : SomeClass[];
targetArray = new SomeClass[someSize];
--- assign the scripts ---
targetArray[random(0,targetArray.length)].SomeFunction();

that way you don’t need to call GetComponent and builtin arrays are much faster than Array.