Search code examples
c#arraysunity-game-enginespritetile

Unity - How to combine sprites into one


I want to make RPG game using Unity2d with the tile feature to draw the game map.

I created a new class inherited from UnityEngine.Tilemaps.Tile and overrided void GetTileData.

In void GetTileData I determine the sprite to show for each tile according to the tile's neighbors.

See the image below. The source image is input from the inspector. The input is only one image like this below. I don't want to make massive input images caus that totally mess up.

But then I have a problem. When in the game I have to extract certain blocks from the source image and combine them into a new sprite to show onto the map as a tile sprite.

enter image description here

Just want to know, if I have the 4 rectangles known, and want to combine them into a sprite like the image above, how can I do that?


Solution

  • There is no easy way to do what you want in code. Simply use a tilemap with smaller base tiles.