public void PopulateLevelFromFile() { if (!hasPopulated) { if (csvFile != null) { int y = 0; _lines = Regex.Split(csvFile.text, "\n"); foreach (string _line in _lines) { int x = 0; string[] _tiles = _line.Split(','); foreach (string _tile in _tiles) { if (_tile != null && !_tile.Equals("")) { GameObject go = InitGameObjectFromKey(_tile); if (go.tag.Equals("Enemy")) { go.transform.position = IsometricHelper.gridToGamePostionUnit(x, y); go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y); GameObject floor = Instantiate(baseTile); floor.transform.position = IsometricHelper.gridToGamePostionTile(x, y); floor.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y); floor.transform.SetParent(tiles.transform); string name = floor.name.Replace("(Clone)", ""); floor.name = name; go.transform.SetParent(hazards.transform); } else { go.transform.SetParent(tiles.transform); go.transform.position = IsometricHelper.gridToGamePostionTile(x, y); go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y); } if (_tile.Contains("enter")) { GameObject _player = Instantiate(player); string name = _player.name.Replace("(Clone)", ""); _player.name = name; _player.transform.position = IsometricHelper.gridToGamePostionUnit(x, y); _player.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y); } } else if (_tile.Equals("")) { GameObject floor = Instantiate(baseTile, IsometricHelper.gridToGamePostionTile(x, y), Quaternion.identity); floor.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y); floor.transform.SetParent(tiles.transform); string name = floor.name.Replace("(Clone)", ""); floor.name = name; } x++; } y++; } hasPopulated = true; } } }