Hello,
#pragma strict
var blocks : GameObject[];
var lastBlock : Transform;
var delay : float = 2;
private var num : int;
private var lastNum : int;
InvokeRepeating("Place",0,delay);
function Place()
{
Debug.Log(num);
var block : GameObject;
while(num == lastNum)
{
num = Random.Range(1,5);
}
lastNum = num;
block = blocks[num];
block.transform.position.z = lastBlock.position.z + 2;
lastBlock = block.transform;
}
Thats my infinite runner script - not amazing, but I am trying to get the basics down before I do anything different. The problem with this script is that sometimes big gaps appear between each separate block – how do I fix this? Thanks.
Currently this is applied to an empty in my scene, with 4 or so blocks at 0,0,0. These blocks are referenced in the array.
I am a sort of advanced beginner, so please explain some complex theories a little dumbed down