Hello folks!
Got a problem with a script that hopefully someone could help me out with.
The point of the script is to spawn platforms aligned perfectly next to each other, without any gap between. The “SpawnDistance” variable sets the distance on how often the platforms should spawn, for example if its set to 20, then they will spawn every 20 unit in unity.
It partly works, platforms with the same size (say 20 units) will spawn perfectly aligned. But at times they spawn with a gap between, so it looks like this: Link to imgur when it instead should look like this: Link to imgur. And i don’t know why this randomly happens. For it to work, all platforms need to be the same size, which they are. Any ideas?
var obj : GameObject[];
var player : Transform;
private var xmin = 0;
var SpawnDistance = 0;
function Spawn() {
var temp = Mathf.FloorToInt(player.position.x/SpawnDistance);
if (temp > xmin){
for(var i = xmin; i < temp; i++){
Instantiate (obj [Random.Range (0, obj.Length)], transform.position, Quaternion.identity);
}
xmin = temp;
}
}