Function in a Function

Hey guys. A lot of you have been helping me with a game I’m trying to make where a target spawns on the side of the screen and moves to the other side. Anyway, I have this script :

var farMovingTarget : Transform;
var spawnInterval : float = 3.0;

InvokeRepeating("SpawnTarget", spawnInterval, 0.0);

function SpawnTarget(){
    var createTarget = Instantiate(farMovingTarget, GameObject.Find("farMovingTargetSpawn").transform.position, Quaternion.identity);
}}

I want that to repeat. I tried putting all that in an Update function which may have been an extremely dumb idea but to a novice programmer it seemed like it would work. Anyway I got an error. Can someone tell me how I can make that code repeat?

put the function outside of update so its an own function.
functions in functions don’t exist outside the function they are in

functions in functions only exist within this single function and only make sense if they encapsulate functionality you need multiple times but only within this one function (if you use them multiple times over different functions, put the functionality in an own function outside).

Wait, So as long as I have the Update function in the script it will update?

Update is called once per frame, every frame.

thats not what you want, you want it at a different rate, so you should put the spawntarget out as an own function and call the invokerepeating from Start() instead so its called once only.

if this here worked, you would kill the machine with more and more parallel spawns after after a second you have piled up FPS spawns that after the 3rd second fire off all few milliseconds killing your app.

Sorry but I have no idea what you’re talking about. It’s my fault not your’s. Don’t I want it to be called more than once?