Hi, I've been trying to create a endless runner type of game as my first project. Right now my script generates a path using tiles, it adds tiles and removes them from the back. Id like to make the tiles random, so that I can add different obstacles to them. I created two prefab tiles but they seem to spawn on top of eachother and I don't know what's wrong with the script. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class TileManager : MonoBehaviour { public GameObject[] tilePrefabs; private Transform playerTransform; private float spawnZ = -5.6f; private float tileLength = 5.0f; private float safeZone = 30.0f; private int amnTilesOnScreen = 7; private int lastPrefabIndex = 0; private List<GameObject> activeTiles; // Use this for initialization private void Start () { activeTiles = new List<GameObject>(); playerTransform = GameObject.FindGameObjectWithTag ("Player").transform ; for (int i = 0; i < amnTilesOnScreen; i++) { if (i < 2) { SpawnTile (0); } else { SpawnTile (); } } } // Update is called once per frame private void Update () { if (playerTransform.position.z - safeZone > (spawnZ - amnTilesOnScreen * tileLength)) { SpawnTile (); DeleteTile (); } } private void SpawnTile(int prefabIndex = -1){ GameObject go; if (prefabIndex == -1) { go = Instantiate (tilePrefabs [RandomPrefabIndex ()]) as GameObject; } else { go = Instantiate (tilePrefabs [prefabIndex]) as GameObject; } go.transform.SetParent (transform); go.transform.position = Vector3.forward * spawnZ; spawnZ += tileLength; activeTiles.Add (go); } private void DeleteTile (){ Destroy (activeTiles [0]); activeTiles.RemoveAt (0); } private int RandomPrefabIndex() { if (tilePrefabs.Length <= 1) { return 0; } int randomIndex = lastPrefabIndex; while (randomIndex == lastPrefabIndex) { randomIndex = Random.Range (0, tilePrefabs.Length); } lastPrefabIndex = randomIndex; return randomIndex; } } https://imgur.com/a/bxtYpKL