void Update() { if (!GameManager.Instance.dead) { while (levelCount < MaxSpawn) { Level s_Level = Instantiate(g_Level.gameObject, transform).GetComponent <Level>(); s_Level.name = "Level " + level; level++; if (curLevel != null) { s_Level.Obstacle = true; if (!firstWall) { int j = 0; for (int i = 1; i < 4; i++) { if (i != ((side + 2) % 4) && i != ((side + 2) % 4)) { availableSides[j] = i; j++; } } side = availableSides[(int)(Lehmer.Next() * j)]; } else { side = 2; firstWall = false; } Wall_Door prev = GetWall(curLevel, side); Wall_Door next = GetWall(s_Level, (side + 2) % 4); prev.Opened = true; next.Opened = true; next.Entrance = true; switch (side) { case 1: pos.x += LevelUnits; break; case 2: pos.z += LevelUnits; break; case 3: pos.x -= LevelUnits; break; } } s_Level.transform.position = pos; curLevel = s_Level; levels.Add(s_Level); levelCount++; } } }
public void GenerateObstacles() { if (obstacles.Count > 0) { foreach (GameObject obj in obstacles) { Destroy(obj); } obstacles.Clear(); } if (enemies.Count > 0) { foreach (GameObject obj in enemies) { Destroy(obj); } enemies.Clear(); } for (int i = 0; i < 4; i++) { Wall_Door wall = GetWall(i); if (wall.Opened) { if (wall.Entrance) { start = i; } else { end = i; } } } int selection; PrefabSet sectionItem; GameObject item; GameObject obs; if (Lehmer.Next() > 0.5) { selection = Mathf.FloorToInt((float)Lehmer.Next() * Sections.Length); sectionItem = Sections[selection]; item = sectionItem.Prefab; obs = Instantiate(item, transform); obs = OffsetPrefab(sectionItem, obs); obstacles.Add(obs); } if (Lehmer.Next() > 0.5) { selection = Mathf.FloorToInt((float)Lehmer.Next() * Enemies.Length); sectionItem = Enemies[selection]; item = sectionItem.Prefab; obs = Instantiate(item, transform); obs = OffsetPrefab(sectionItem, obs); enemies.Add(obs); } }