コード例 #1
0
    private void createLevel()
    {
        Tiles = new Dictionary <Point, TileScript>();

        //Defines the size of the map and the tiles that are at certain positions
        string[] mapData = ReadLevelText();


        //Converts the mapData into x and y coordinates
        int mapX = mapData[0].ToCharArray().Length;
        int mapY = mapData.Length;

        Vector3 minTile;
        Vector3 maxTile;

        //Calculates the world's start point.
        Vector3 worldStart = Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height));

        for (int y = 0; y < mapY; y++) //The y positions of the tiles
        {
            char[] newTiles = mapData[y].ToCharArray();

            for (int x = 0; x < mapX; x++) // The x positions of the tiles
            {
                //Places the tile in the world
                PlaceTile(newTiles[x].ToString(),
                          x,
                          y,
                          worldStart);
            }
        }


        minTile = Tiles[new Point(0, 0)].transform.position;               // find the very first tile placed.
        maxTile = Tiles[new Point(mapX - 1, mapY - 1)].transform.position; // find the very last tile placed.


        moveCamera.SetMinLimits(new Vector3(minTile.x - TileSize, minTile.y + TileSize));              //sets the minimum limits of the camera using the first tile placed.

        moveCamera.SetMaxLimits(new Vector3(maxTile.x + 2 * TileSize, maxTile.y - 2 * TileSize, -10)); // sets the max limits of the camera using the last tile placed.

        SpawnPortal();                                                                                 // spawns th portals above the tiles.
    }