0
\$\begingroup\$

As seen in the images, changing the value of 'spawnZ' affects the distance between the initial platform and the first generated platform but afterwards it has no affect whatsoever.

public GameObject[] tilePrefabs;

public float spawnZ = 10f;
public float tilelength;
public int amnTilesOnScreen = 5;
public Transform playerTransform;


// Use this for initialization
void Start () {
    for (int i = 0; i<amnTilesOnScreen; i++)
    {
        SpawnTile();
    }
}

// Update is called once per frame
void Update () {
if(playerTransform.position.z>(spawnZ - amnTilesOnScreen * tilelength))
    {
        SpawnTile();
    }
}

private void SpawnTile(int prefabIndex = -1) {
    GameObject go;
    go = Instantiate(tilePrefabs[0]) as GameObject;
    go.transform.SetParent(transform);
    go.transform.position = Vector3.forward * spawnZ;
    spawnZ += tilelength;

}

enter image description here enter image description here enter image description here

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Try changing the last line of SpawnTile() to this:

spawnZ += tilelength + desiredGapDistance;
\$\endgroup\$
1
  • \$\begingroup\$ This answer would be even better if it explained why you expect this change will resolve the problem / what effect it should have and why. \$\endgroup\$
    – DMGregory
    May 24, 2018 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .