My trigger is not working right

hello there i am making a video game that require a obstacle generator similar to the one in flappy birds when the character goes though the trigger located in the center of the obstacles it is suppose to spawn another obstacle a few units up one at a time but it spawns a whole bunch in the air which slows down my computer can you guys help me make it spawn one at a time thx here is my script

#pragma strict

var max : float = 5;
var min : float = 0;
var obstacle : GameObject;
var regenerate : boolean = false;
var far : float = 0;
var yes : boolean = true;

function Start () {

}

function Update () {

var x = Random.Range ( min, max);

var y = far + transform.position.y;

if(regenerate){

Instantiate( obstacle, Vector3(x,y,0),Quaternion.identity);
regenerate = (false);

}

}

function OnTriggerEnter2D (other: Collider2D) {
{
regenerate = (true);}

}

  1. Add Box Collider 2D to your obstacle that contains your script. Enable Is Trigger in this box collider.
  2. Add Box Collider 2D and Rigidbody 2D to your character.
  3. (Optional) Change gravity scale value to 0 in rigidbody if you don’t need Unity physics engine.

By the way you don’t need the update function/loop in your script. Now it calculates random number and uses transform.position.y on every frame. Use Regenerate function call when “other” enters into trigger 2D.

var max : float = 5;
var min : float = 0;

var obstacle : GameObject;

var far : float;

var x : int;
var y : int;

function Regenerate () {

x = Random.Range (min, max);

y = far + transform.position.y;

Instantiate(obstacle, Vector3(x,y,0),Quaternion.identity); 

}

function OnTriggerEnter2D (other: Collider2D) {
    Regenerate();
}