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