Well the idea is every second to spawn the original game object 5 meters in front of the previous one. Example say 0 is the mesh: 0--0--0--0--0 and by the fifth zero five seconds have gone on and on the 6th second it will look like this: 0--0--0--0--0--0. Now I know I should use instantiate to spawn a new mesh (without destroying the original), and combine it with Time.deltaTime.
Here's what I have come up with:
function Update () {
//I don't know how to format the instantiate , so here is what I think it would be like:
gameObject = instantiate
var translation = Time.deltaTime * 5;
transform.Translate (0, 0, translation);
}
I really have very little experience in programming, although I do know how it works.
var preFab : GameObject; //Set this in the inspector.
var spawnPnt : Vector3 = Vector3(0,0,0); // set the initial spawn point
var incrementVec : Vector3 = Vector3(0,0,5.0); // set the offset per spawn
function Start()
{
InvokeRepeating("Spawn",0.5, 1.0); //Set up a call to Spawn() every second
}
function Spawn()
{
Instantiate(preFab, spawnPnt, Quaternion.identity); //Instantiate your object at spawnPnt
spawnPnt += incrementVec; //Set the next spawnPnt
}
// this script should NOT be added to the object you want to instantiate,
// but to any other one (empty gameObject, for example).
// the time that shall pass before a new instance is created
public var timeStep = 5.0;
// the object that shall be instantiated
public var myObject : Transform;
// the move offset between objects
public var moveOffset : Vector3 = (0,0,2);
// the last time a new instance was created
private var lastTime : float;
private var number = 0;
function Start()
{
// start at zero time difference
lastTime = Time.time;
}
function Update()
{
// compare current time to last time a object was instantiated
if(Time.time - lastTime > timeStep)
{
// keep track of the number of objects
number++;
// instantiate your object at a offset position with no rotation
Instantiate(myObject, moveOffset * number, Quaternion.identity);
}
}
`Time.deltaTime` returns the seconds since the last `Update()` was called, and is commonly used to make movements and other things frame rate independent. For your case, `Time.time` suits better, because it returns the total amount of time since you started your game.