예제 #1
0
        private void AddStartingBlockers()
        {
            List <Vector2Int> soilTiles = new List <Vector2Int>();

            foreach (Vector3Int pos in groundTilemap.cellBounds.allPositionsWithin)
            {
                Vector2Int tilePos  = pos.ToVector2Int();
                Vector3    worldPos = tilePos.TileToWorld();
                TileBase   tile     = groundTilemap.GetTile(pos);
                if (regularSoilType.Contains(tile))
                {
                    soilTiles.Add(tilePos);
                    float random = Random.value;
                    if (random < 0.45)
                    {
                        CropBlocker weed = Instantiate(weedPrefab, worldPos, Quaternion.identity);
                        weed.RegisterBlocker();
                    }
                }
            }

            int counter = 0;

            soilTiles.OrderBy(tile => Random.value)
            .Take(NumberOfRocks + NumberOfStumps)
            .ForEach(tile => {
                CropBlocker blocker = CropManager.Instance.GetBlocker(tile);
                if (blocker != null)
                {
                    CropManager.Instance.RemoveBlocker(tile);
                    Destroy(blocker.gameObject);
                }
                Instantiate(counter++ < NumberOfRocks ? rockPrefab : stumpPrefab, tile.TileToWorld(),
                            Quaternion.identity);
            });
        }