using System.Collections; using System.Collections.Generic; using UnityEngine; public class SectionTriger : MonoBehaviour { public static int counter =0; public GameObject[] roadSection; public float speed = -100f; int headroom = 5; void Start() { if(counter ==0){ } } private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Trigger")) { int randomNumber = Random.Range(0, roadSection.Length); if(counter == 0){ for(int i=0; i <= headroom; i++){ Instantiate(roadSection[Random.Range(0, roadSection.Length)], new Vector3(0, 0, other.transform.position.z + (speed * (i))), Quaternion.identity); } Destroy(other.transform.parent.gameObject); } Instantiate(roadSection[randomNumber], new Vector3(0, 0, other.transform.position.z + (speed * (headroom+1))), Quaternion.identity); counter++; } } }