//logic to add new tile to current map private void NewTileButtonLogic() { //check that map exists if (map) { //create a gameobject to hold the tile GameObject newTileObject = new GameObject("Tile"); //attach the tile to the object TileBehavior createdTile = newTileObject.AddComponent <TileBehavior>(); //assign values to new tile createdTile.position.xPos = newTileX; createdTile.position.yPos = newTileY; createdTile.value.type = newTileType; //check that this tile does not already exist if (!map.CheckForSameInBoard(createdTile, 0)) { //attach this new object to the maps object as child newTileObject.transform.parent = map.gameObject.transform; //add this new tile to the map map.AddTileToBoard(createdTile); //draw the map again GetMapDetails(); } //if it does, destroy the object after comparison else { DestroyImmediate(newTileObject); } } }