void OnTriggerEnter2D(Collider2D col) { if(col.gameObject.CompareTag("Player")) { Debug.Log("Player passed trigger"); if(prev) { Destroy(prev.gameObject); } prev = terrain; terrain = next; transform.position += new Vector3(36f, 0f, 0f); GameObject nextGO = (GameObject)Instantiate(terrainPrefab, transform.position, Quaternion.identity); next = nextGO.transform; nextCaveGenerator = next.GetComponent<CaveGenerator>(); //nextHillGenerator = next.GetComponent<HillGenerator>(); nextPlatformGenerator = next.GetComponent<PlatformGenerator>(); nextCaveGenerator.Generate(); nextPlatformGenerator.Append(); } }