/// <summary> /// Method to spawn an animal into the world /// </summary> void SpawnAnimal() { // generate random ints xSpawn = Random.Range(0, forestGen.sizeX); ySpawn = Random.Range(0, forestGen.sizeX); // create the spawn position spawnPos = new IntVector2((int)xSpawn, (int)ySpawn); // get the cell in which the animal should spawn spawnCell = forestGen.GetCell(spawnPos); // check to make sure the position is unique for (int i = 0; i < animalSpawns.Count; i++) { if (spawnPos == animalSpawns[i]) { samePos = true; } } // add it to the list of spawnPositions animalSpawns.Add(spawnPos); if (samePos == false) { // check to make sure the tile isn't already on fire if (spawnCell.OnFire == false) { // get the world position of the forest cell Vector3 tempSpawn = new Vector3(spawnCell.transform.position.x, spawnCell.transform.position.y + 0.2f, spawnCell.transform.position.z); // instantiate the object in the world on the cell GameObject tempObj = Instantiate(animal, tempSpawn, Quaternion.identity); // increment the animal spawn counter animalCount++; } } }
/// <summary> /// Retrieves all the neighbors of this cell and adds them to the neighbors list /// </summary> private void GetNeighbors() { //The coordinates of this cell IntVector2 position = gameObject.GetComponent <ForestCell>().coordinates; //The forest this cell is in ForestGenerator forest = gameObject.GetComponentInParent <ForestGenerator>(); //Check every direction for (int i = 0; i < 4; i++) { //Calculate the coordinates of each direction IntVector2 cellToGet = position + ForestDirections.ToIntVector2((Direction)i); //If the coordinates calculated are part of the forest, retrieve that cell and add it to the list if (forest.ContainsCoordinates(cellToGet)) { ForestCell temp = forest.GetCell(cellToGet); neighbors.Add(temp); } } neighborsRetrieved = true; }