private void ReadMap() { for(int z=0; z<height; z++) { string line = reader.ReadLine(); List<GameObject> sublist = new List<GameObject>(); for(int x=0; x < width; x++) { // Create your tile object. GameObject tile = Object.Instantiate(tileObject) as GameObject; tile.transform.parent = gameObject.transform; DontDestroyOnLoad(tile); // for passing around // Change its position to this grid reference. tile.transform.position = new Vector3(x * spacing, tileObject.transform.position.y, z * spacing); tileScript = tile.GetComponent<TileScript>(); tileScript.x = z; tileScript.y = x; // yeah deal with it int inType = line[x] - 48; switch(inType) { case(0)://grass { tileScript.tileType = TileScript.TileType.GRASS; tileScript.SetTexture(textures[(int)tileScript.tileType]); break; } case(1)://water { tileScript.tileType = TileScript.TileType.WATER; break; } case(2)://tree { tileScript.tileType = TileScript.TileType.GRASS; tileScript.SetTexture(textures[(int)tileScript.tileType]); tileScript.AddSpecialTerrain(ObjectFactory.getInstance().create("tree")); break; } case(3)://factory { tileScript.tileType = TileScript.TileType.GRASS; tileScript.SetTexture(textures[(int)tileScript.tileType]); tileScript.AddSpecialTerrain(ObjectFactory.getInstance().create("factory")); break; } case(4)://city { tileScript.tileType = TileScript.TileType.GRASS; tileScript.SetTexture(textures[(int)tileScript.tileType]); tileScript.AddSpecialTerrain(ObjectFactory.getInstance().create("city")); break; } case(5)://fort { tileScript.tileType = TileScript.TileType.GRASS; tileScript.SetTexture(textures[(int)tileScript.tileType]); tileScript.AddSpecialTerrain(ObjectFactory.getInstance().create("fort")); break; } case(6)://barracks { tileScript.tileType = TileScript.TileType.GRASS; tileScript.SetTexture(textures[(int)tileScript.tileType]); tileScript.AddSpecialTerrain(ObjectFactory.getInstance().create("barracks")); //At(x,z).AddSpecialTerrain(specialTerrain); break; } default: throw new System.Exception ("why you doin this shit mang? " + inType); break; } sublist.Add(tile); } //reader.Read(); tiles.Add(sublist); } string line2; while((line2 = reader.ReadLine()) != null) { ReadSpecialTerrainLine(line2); } // Done reading tiles, now do the objects }