Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        tile[,] tiles    = mazeGenerator();
        GameObject[,] go = new GameObject[columns, rows];
        //instantiate buildings
        for (int i = 0; i < tiles.GetLength(0); ++i)
        {
            for (int j = 0; j < tiles.GetLength(1); ++j)
            {
                if (tiles[i, j] == tile.BUILDING)
                {
                    //create a building
                    go[i, j] = Instantiate(BuildingPrefab, new Vector3(i * 20, 0, j * 20), Quaternion.identity);
                }
            }
        }

        for (int i = 0; i < columns; ++i)
        {
            for (int j = 0; j < rows; ++j)
            {
                if (tiles[i, j] == tile.BUILDING)
                {
                    Building b         = go[i, j].GetComponent <Building>();
                    int      nextIndex = i + 1;
                    if (nextIndex > 0 && nextIndex < columns)
                    {
                        if (tiles[i + 1, j] == tile.BUILDING)
                        {
                            Building b2 = go[i + 1, j].GetComponent <Building>();
                            b.AddNeighbor(b2);
                        }
                    }
                    nextIndex = j + 1;
                    if (nextIndex > 0 && nextIndex < rows)
                    {
                        if (tiles[i, j + 1] == tile.BUILDING)
                        {
                            Building b2 = go[i, j + 1].GetComponent <Building>();
                            b.AddNeighbor(b2);
                        }
                    }

                    nextIndex = i - 1;
                    if (nextIndex > 0 && nextIndex < columns)
                    {
                        if (tiles[i - 1, j] == tile.BUILDING)
                        {
                            Building b2 = go[i - 1, j].GetComponent <Building>();
                            b.AddNeighbor(b2);
                        }
                    }

                    nextIndex = j - 1;
                    if (nextIndex > 0 && nextIndex < rows)
                    {
                        if (tiles[i, j - 1] == tile.BUILDING)
                        {
                            Building b2 = go[i, j - 1].GetComponent <Building>();
                            b.AddNeighbor(b2);
                        }
                    }
                }
            }
        }
    }