// Spawn a new pathwalker. private void SpawnPathWalker() { int random = Random.Range(0, 101); if (random < mapGenerator.PathWalkerChanceToSpawn) { PathWalker pathWalker = Instantiate(mapGenerator.pathWalkerPrefab, transform.position, Quaternion.identity, mapGenerator.pathWalkersContainer).GetComponent <PathWalker>(); pathWalker.Initialize(position, maxSteps / 2); } }
// Initialize the map generation public void InitGeneration() { origin = new Vector2(xSize * mapScale / 2, ySize * mapScale / 2); Camera.main.transform.position = new Vector3(origin.x, origin.y, Camera.main.transform.position.z); // Destroy all previous tiles, collectibles and pathwalkers foreach (Transform tile in tilesContainers) { Destroy(tile.gameObject); } foreach (Transform collectible in collectiblesContainers) { Destroy(collectible.gameObject); } foreach (Transform walker in pathWalkersContainer) { Destroy(walker.gameObject); } // Clear all lists pathWalkers.Clear(); ammoChests.Clear(); weaponChests.Clear(); // Fill the list with empty tiles tiles = new List <List <GameObject> >(); for (int x = 0; x < xSize; x++) { tiles.Add(new List <GameObject>()); for (int y = 0; y < ySize; y++) { tiles[x].Add(null); } } // Initialize purcentage purcentageForward = chanceForward; purcentageLeft = purcentageForward + chanceLeft; purcentageRight = purcentageLeft + chanceRight; purcentageBackward = purcentageRight + chanceBackward; // Create a new pathwalker PathWalker pathWalker = Instantiate(pathWalkerPrefab, origin, Quaternion.identity, pathWalkersContainer).GetComponent <PathWalker>(); pathWalker.Initialize(new Vector2(xSize / 2, ySize / 2), PathWalkerDistance); }