//check if the surrounding area is safe to give birth around public bool safeToGiveBirth() { float x = pos.x; float y = pos.y; Vector2 up = new Vector2(x, y + 1); x = pos.x; y = pos.y; Vector2 down = new Vector2(x, y - 1); x = pos.x; y = pos.y; Vector2 right = new Vector2(x + 1, y); x = pos.x; y = pos.y; Vector2 left = new Vector2(x - 1, pos.y); return(!gs.isOccupied(up) && !gs.isOccupied(down) && !gs.isOccupied(right) && !gs.isOccupied(left)); }
// Update is called once per frame IEnumerator spawnTrees() { while (true) { yield return(new WaitForSeconds(secondsTillNextSpawn)); Vector2 spawnPoint = pos; var food = (GameObject)Resources.Load("Prefabs/Food"); //left spawnPoint.x -= 1; if (!gs.isOccupied(spawnPoint)) { var left = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); left.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //top left spawnPoint.y += 1; if (!gs.isOccupied(spawnPoint)) { var left = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); left.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //bottom left spawnPoint.y -= 2; if (!gs.isOccupied(spawnPoint)) { var left = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); left.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //right spawnPoint = pos; spawnPoint.x += 1; if (!gs.isOccupied(spawnPoint)) { var right = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); right.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //top right spawnPoint.y += 1; if (!gs.isOccupied(spawnPoint)) { var right = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); right.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //bottom right spawnPoint.y -= 2; if (!gs.isOccupied(spawnPoint)) { var right = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); right.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //top spawnPoint = pos; spawnPoint.y -= 1; if (!gs.isOccupied(spawnPoint)) { var up = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); up.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } //bottom spawnPoint.y += 2; if (!gs.isOccupied(spawnPoint)) { var down = Instantiate(food, gs.getGridPosition(spawnPoint), Quaternion.identity); down.transform.parent = GameObject.FindGameObjectWithTag("foodContainer").transform; } } }