示例#1
0
    int[] findOpenSpaceNear(int x, int z)
    {
        while (true)
        {
            //try to find open space.
            WallScript ws = WallArray[x][z].GetComponent <WallScript>();
            if (ws.GetHeight() == 1 && ws.getLockState() == false)
            {
                //this X and Y location is good. Break.
                Debug.Log("Found open space at x:" + x + ", z:" + z);
                break;
            }

            //This space isn't open, get one nearby then loop.
            else
            {
                //Get random new location nearby.
                int dir = rng.Next() % 4;
                switch (dir)
                {
                case 0: x++; break;

                case 1: x--; break;

                case 2: z++; break;

                case 3: z--; break;
                }

                //make sure we don't go OOB.
                if (x > mazeSize)
                {
                    x--;
                }
                else if (x < 0)
                {
                    x++;
                }
                if (z > mazeSize)
                {
                    z--;
                }
                else if (z < 0)
                {
                    z++;
                }
            }
        }
        return(new int[2] {
            x, z
        });
    }