//a tile has been excavated and needs to be updated to a new tile prefab //this also draws the new tile, so that each tile can be updated individually and the whole map doesn't have to be redrawn public void UpdateTile(byte tileByte, string tileType, Vector2 updatedTileCoords) { int xCoord = (int)updatedTileCoords.x; int yCoord = (int)updatedTileCoords.y; //if chosen tileType already equals existing tileType, just update tile's tileByte. tile tile tile tile TerrainTile existingTile = terrainMapArray[xCoord, yCoord].GetComponent <TerrainTile>(); string existingTileType = existingTile.tileType; if (existingTileType.Equals(tileType)) { existingTile.tileByte = tileByte; return; } existingTile.needUpdatingAndRemoval = true; //grab the old tile's screen position information //Transform tileScreenTransform = terrainMapArray [xCoord, yCoord].transform; //print (tileScreenTransform.position.ToString ()); //add the appropriate terrain tile (decided elsewhere) to the place in the terrain map array GameObject tileToUse = FindTerrainTile(tileType); TerrainTile tileParameters = tileToUse.GetComponent <TerrainTile> (); tileParameters.tileCoords = updatedTileCoords; //give the new tile the old tile's coords tileParameters.tileByte = tileByte; //give the new tile it's tileByte tileParameters.tileType = tileType; //give the new tile it's tileType //destroy the old tile //terrainMapArray [xCoord, yCoord].GetComponent<TerrainTile> ().pendingDestruct = true; //tell the old tile to destroy itself, doesn't work? GameObject tileToDestroy = terrainMapArray[xCoord, yCoord]; TerrainTile destroyTile = tileToDestroy.GetComponent <TerrainTile> (); destroyTile.PrepForPendingDestruct(); //add the new tile to the terrainMapArray terrainMapArray [xCoord, yCoord] = tileToUse; //change depending on the tileScale var transformX = xCoord * tileScale; var transformY = yCoord * tileScale; //change depending on origin transformX += origin.x; transformY += origin.y; //draw the tile var temp = Instantiate(terrainMapArray [xCoord, yCoord]) as GameObject; temp.transform.position = new Vector3(transformX, transformY, 0.0f); //ehh might work? //update the terrain bool map if (tileType.Equals("excavatedTile")) { terrainBoolMap[xCoord, yCoord] = false; } else { terrainBoolMap[xCoord, yCoord] = true; } //the tile itself should take care of it's parameters for being excavated and such }