Scroll a given sprite from a tileset

Hello
I’m learning unity with a small topdown tilemap rpg project.
I have a tilemap build from multiple tiles from a tileset. Some tiles are water and I would like to animate these tiles with a vertical scrolling (see attached gif)

I wrote this ‘scroll’ script, attach it to the tilemap:

    void Update()
    {
        float offsetX = Time.time * ScrollX;
        float offsetY = Time.time * ScrollY;
        var myTileData = GameManagers.Map.GetTileData(transform.position.ToVector2Int());

        if (myTileData != null)
        {
            var tile = ((Tile)myTileData.TileBase);
            tile.sprite.texture.wrapMode = TextureWrapMode.Repeat;
            var rend = GetComponent<Renderer>();
            rend.material.SetTextureOffset(tile.sprite.texture.name, new Vector2(offsetX, offsetY));
        }
    }

But nothing happens.

If I use
material.mainTextureOffset = new Vector2(offsetX, offsetY);
the whole tileset is scrolled.

How can I make a tile scroll only on its sprite and not the full tileset sprite ?

Thanks

8207568--1071228--scroll.gif

I don’t think that you can do that with Tilemaps. You can make an animated water tile and stretch the sprite (via its transform) to make a larger area but you can’t animate the texture for a single tile - there’s one renderer for the whole tilemap. At least not as far as I know.

Ok, I see.
Maybe I can put all tiles to scroll on another tilemap and scroll all tiles in this tilemap ?

I don’t believe that that would work though you could try it. IIRC the tilemap renderer doesn’t support this sort of operation in the same way that a renderer on a GameObject does. As far as I know (and I could be wrong) the only way to do animation on tilemaps is to use their animation feature or to animate an individual tile’s transform matrix.

I have water animation running in the game I’m working on and just use animated tiles (the ones on Tilemap Extras). Don’t forget you can resize the visible aspect of a tile via its transform matrix.