public void GrowApples(int count = 20) { for (int i = 0; i < count; i++) { MapTile tile = GetRandomTile(); tile.AddItem(Instantiate(applePrefab).GetComponent <Item>()); } }
public IEnumerator AddItems(List <MapRegion> regions) { isGenerating = true; foreach (MapRegion region in regions) { foreach (SO_Item item in items) { int chance = Random.Range(1, 101); if (item.CanBeInThisRegion(region)) { if (chance < item.apparitionRatePerRegion) { Vector2 pos = new Vector2(); while (pos == new Vector2()) { MapTile t = region.tiles[Random.Range(0, region.tiles.Count)]; if (!t.isOccuped) { pos = t.position + new Vector2(0.5f, 0.5f); t.AddItem(); } } GameObject instance = Instantiate(item.prefab); instance.transform.position = pos; } } } } isGenerating = false; yield return(null); }