Instantiated functions

In my game I Instantiate a lot of AI, which is a cloned prefab, which has cloned script components, which has cloned functions. Is it ok to have so many cloned functions only used by that cloned AI or should I have one function that lives somewhere and gets called by all the cloned AI?

AIscript.js

function Start()
{
    doStuff();
}

function doStuff()
{
     // do stuff to AI.
}

Or

LevelScript.js

function Start()
{
    for(var i = 0; i<10; i++)
    {
        enemy = Instantiate( prefab, pos, rot );
        doStuff( enemy );
        yield WaitForSeconds( 1 );
    }

}

function doStuff( AI )
{
    //do stuff to AI.
}

Should I have AIscript functions that get cloned with all my AI or level Ai functions that wait to get called?

I hope this make sense.

I don’t think there is any difference. Somewhere inside Unity, there is a loop on all Monobehaviour to execute all the function. So either you do the loop or Unity is irrelevant in my opinion.

I’d like to hear from a Unity tech on this, but it seems like you’d save on-media bytes by using one script, or making often-used functions static if possible. Execution time probably no different, but again, I’d like Unity’s opinion.

When you have multiple objects that use the same script, each one acts independantly, so I think that it would take more cycles to deal with a bunch of copies of the same script.

However, I think it would be more difficult to implement the one-script-running-multiple-objects plan. I wouldn’t worry about it unless you notice performance problems.