How I can stop the spawning process ?

I am making a game like Mario but with a plane (yeah, I know it is a bit stupid) and I want at begining to spawn some hills at my ground. The problem is I have an script what spawn hills continous and it give me lag. So, I want to know what code script to write to put a limit of hills and when the limit is reached, the spawning stops. Here is the script and a picture of my game:


P.S.: IF YOU HAVE ANOTHER SCRIPT WHAT DO THE SAME THING, BUT IS SIMPLE, PLEASE TO TELL ME.

I would put the spawning in a method and call the method from the method itself.

void Start ()
{
Invoke(“SpawnStuff”, spawnTime);
}

void SpawnStuff ()
{
// do spawn logic here
Invoke(“SpawnStuff”, spawnTime);
}

Try keeping your update as logic free as possible. Best case would be to spawn from a coroutine and keep the game more smooth and load faster.