void generateMapFromFile(string name) { FileReader fr = new FileReader(); string[] mapArr = fr.textAssetToStrArray(name); map = new List<List<Tile>>(); GameObject tilePrefab; int xCoord = 0; MapWidth = mapArr.Length; foreach (string line in mapArr) // for each column { // The finished product we're building List<Tile> column = new List<Tile>(); // The bits of the file we're building from string[] tileStrArr = line.Split(new string[] { ";" }, StringSplitOptions.None); int yCoord = 0; MapHeight = tileStrArr.Length; foreach (string tileStr in tileStrArr) { string[] attributes = tileStr.Split(new string[] { "," }, StringSplitOptions.None); string env = attributes[0]; //Get string representation of tile type int height = Int32.Parse(attributes[1]); //get int representation of tile height Vector3 position = new Vector3(xCoord, (height / 4.0f), yCoord); Quaternion rotation = Quaternion.Euler(new Vector3()); switch (height) // Set height { case 1: tilePrefab = TilePrefab_e0; break; case 2: tilePrefab = TilePrefab_e1; break; case 3: tilePrefab = TilePrefab_e2; break; default: tilePrefab = TilePrefab_e0; break; } GameObject block = Instantiate(tilePrefab, position, rotation) as GameObject; Tile tile = block.GetComponent<Tile>(); switch (env) // Create block based on height, type { case "barrier": tile.setEnvironment("barrier"); break; case "stone": tile.setEnvironment("stone"); break; case "grass": tile.setEnvironment("grass"); GameObject bsh = Instantiate(decoBush, position, rotation) as GameObject; break; case "plains": tile.setEnvironment("plains"); break; case "forest": tile.setEnvironment("forest"); break; } tile.gridPosition = new Vector2(xCoord, yCoord); // Add tile's own position on grid to the tile column.Add(tile); // Add tile to the column yCoord += 1; // Increment yCoord for next run } map.Add(column); //Add column to map xCoord += 1; //Increment xCoord for next run } // Initialize center holder values mapcenterX = MapWidth / 2; mapcenterY = MapHeight / 2; mapCenter = new Vector3(mapcenterX, 0.0f, mapcenterY); groundPlane.transform.position = mapCenter; //set camera position to the center of the map //maybe do something like this whenever the controlling team switches, set camera position to average // position of the new team GameObject.Find("CameraCenter").transform.position = new Vector3(mapcenterX, 0, mapcenterY); Instantiate(groundPlane, mapCenter, Quaternion.Euler(new Vector3())); }