Esempio n. 1
0
    void Init()
    {
        gridPositions.Clear();

        for (var i = 1; i < Cols - 1; ++i)
        {
            for (var j = 1; j < Rows - 1; ++j)
            {
                gridPositions.Add(new Vector3(i, j, 0.0f));
            }
        }

        boardHolder = new GameObject("Board").transform;

        for (var i = 0; i < Cols; ++i)
        {
            for (var j = 0; j < Rows; ++j)
            {
                GameObject sprite = Floor.GetRandomSprite();
                if (i == 0 || i == Cols - 1 || j == 0 || j == Rows - 1)
                {
                    sprite = Walls.GetRandomSprite();
                }

                GameObject instance = Instantiate(sprite, new Vector3(i, j, 0.0f), Quaternion.identity) as GameObject;
                instance.transform.SetParent(boardHolder);
            }
        }
    }
Esempio n. 2
0
    void LayoutSprites(SpritePool sprites, Amount amount)
    {
        for (var i = 0; i < Random.Range(amount.Min, amount.Max + 1); ++i)
        {
            int     j         = Random.Range(0, gridPositions.Count);
            Vector3 randomPos = gridPositions[j];
            gridPositions.RemoveAt(j);

            GameObject sprite = sprites.GetRandomSprite();
            Instantiate(sprite, randomPos, Quaternion.identity);
        }
    }