public void DamageTile(TileLayer layer, Vector3Int position, int amount, HitDirection hitDirection) { Tilemap tilemap = GetTilemap(layer); TileBasic tile = tilemap.GetTile <TileBasic>(position); if (tile != null) { if (!_terrainWorldTiles.ContainsKey(position)) { // Check if the tile is destroyed instantly if (amount > tile.Item.WorldTileDamage) { WorldItem worldItem = WorldItem.CreateWorldItem(new InstanceItem(tile.Item), tilemap.CellToWorld(position)); tilemap.SetTile(position, null); } // else make a worldtile and apply damage else { _terrainWorldTiles.Add(position, new WorldTile { Damage = amount }); // Create a break effect tile to represent damage EffectTilemap.SetTile(position, CreateBreakEffectTile(hitDirection, amount, tile.Item.WorldTileDamage)); } } else { // Get world tile from dictionary and apply damage _terrainWorldTiles[position].Damage += amount; // check for tile destruction if (_terrainWorldTiles[position].Damage >= tile.Item.WorldTileDamage) { _terrainWorldTiles.Remove(position); WorldItem worldItem = WorldItem.CreateWorldItem(new InstanceItem(tile.Item), tilemap.CellToWorld(position)); tilemap.SetTile(position, null); EffectTilemap.SetTile(position, null); } else { // Update the break effect tile EffectTilemap.SetTile(position, CreateBreakEffectTile(hitDirection, _terrainWorldTiles[position].Damage, tile.Item.WorldTileDamage)); } } } }