// Method that removes an occupant from a grid tile public void RemoveTerrainTileOccupant(GridTile tile) { for (int i = 0; i < tile.occupants.Count; i++) { // if type is Terrain Generated if (tile.occupants[i].type == GridTileOccupant.OccupantType.TerrainGenerated) { // Get the terrainObject script from the occupant TerrainObject terrainObj = tile.occupants[i].obj.GetComponent <TerrainObject>(); // Get the submeshes that should be in this particular terrain object from the biomemeshes Mesh[] objMeshes = thisTerrainController.biomeMeshes[terrainObj.biome].mesh[terrainObj.objectNR]; // create an object of with info of the object that should be removed // for each of these meshes for (int k = 0; k < objMeshes.Length; k++) { Vector3 startVert = objMeshes[k].vertices[0]; startVert = new Vector3(startVert.x * tile.occupants[i].scale.x, startVert.y * tile.occupants[i].scale.y, startVert.z * tile.occupants[i].scale.z); // scale, rotate and move the vertex according to inputs startVert = tile.occupants[i].rotation * startVert; startVert = startVert + (tile.occupants[i].position - terrainObj.transform.position); int numVerts = objMeshes[k].vertexCount; // Add a copy of the mesh that should be removed. Move, rotate and scale it as it is in the game. terrainObj.RemoveMesh(new MoveMeshObj(startVert, numVerts)); } } } for (int i = 0; i < tile.occupants.Count; i++) { // if type is Terrain Generated if (tile.occupants[i].type == GridTileOccupant.OccupantType.TerrainGenerated) { // set the tile occupant to null tile.occupants.RemoveAt(i); } } }