Clone an object move it along the y axes then delete it.

So as the title suggests i wan’t an object to be repeated along on the x axes so that it begins the next object where the last object ended. But this will take up heaps of ram so i want it to be made so that only Four/five objects are in the scene at any given time.

alt text

you need only to create a cube primitive and set the x scale to 2, and put this script in the camera, and asign the objectprefab variable with your cube.

#pragma strict
var objectprefab : GameObject;
var whatIhavehere : GameObject[];
var objectwidht : float = 2;
var numberofobjects : int;
var zoffset : float = 2;
var x : int;
var proxblock : int;

function Start () {

whatIhavehere = new GameObject[20];
numberofobjects = 2;
transform.position.x += 3*Time.deltaTime;
x =Mathf.FloorToInt(transform.position.x);
proxblock = x+numberofobjects;

}


function Update () 
{

// transform a float position in a int position,
x =Mathf.FloorToInt(transform.position.x);
if(x+(numberofobjects) == proxblock)
{
var posi : Vector3;
posi = Vector3( x+(numberofobjects*objectwidht),transform.position.y,transform.position.z+zoffset);
	whatIhavehere[foundone()] =Instantiate(objectprefab,posi,objectprefab.transform.rotation);
	proxblock += objectwidht;
}


transform.position.x += 3.0*Time.deltaTime;


}

function foundone () 
{
	for(var i=0;i<whatIhavehere.Length;i++)
	{
		if(whatIhavehere *== null)*
  •  	return(i);*
    
  •  else*
    
  •  {*
    

_ if((whatIhavehere*.transform.position.x -x)<x-proxblock)_
_
{_
_ Destroy(whatIhavehere);
return(i);
}
}
}
return(i);
}*_

Thanks for the fast reply, yep that will help me.
what i had so far was
var theObject:GameObject;

var X_Axes:float = 0;
var Y_axes:float = 1;
var Move_X:float = -4;
var max = 3;
var delay : float = 2.55;
function Start(){
    StartCoroutine(spawn());
}
 
    function spawn() : IEnumerator {
       for (var i = 0;max > 1; i++) {
           yield WaitForSeconds(delay);
         //  var theNewPos= new Vector3 transform.up * 10;
           var thePosition = transform.TransformPoint(X_Axes, Y_axes , 0);
           var go : GameObject = Instantiate(theObject);
           go.transform.position = thePosition;
           X_Axes = X_Axes + Move_X;
           
        }
    }