0
\$\begingroup\$

I am trying to make a simple 2D square grid for a map UI. The game itself is also 2D and the player can only make discrete movements between the square, but the player view is first person (you see a painted view of the scenery at that square), so the 2D square map is just for the map, not the main game view.

So the map would look something like this:

2D Map

This would be used in the minimap, and also in a semi-fullscreen overlay map view that the player can pull up.

What is the best way to do this in Unity?

I tried using a GridLayoutGroup and adding one Image child for each square. For a simple 100x100 map, though, this leads to 10,000 game objects each just representing one tile in the map.

It seems like this is what Tilemaps would be good at, but I don't see a way to use Tilemaps in the minimap or an overlay on top of the main view.

\$\endgroup\$
1
  • \$\begingroup\$ I've seen this achieved before using a sprite tilesheet/atlas that contains all possible map tiles. So you've got a single texture with all tiles, and a single texture for the map/world that uses a custom shader that reads map data and stitches together the appropriate tiles from the atlas. \$\endgroup\$
    – Basic
    Commented May 30, 2023 at 12:34

1 Answer 1

2
\$\begingroup\$

You could use a setup with two cameras. The first one pointing at the 1st person view of the player. The second one pointing at a Tilemap and rendering to a render texture by setting that render texture as the "Target Texture" in the camera component. That render texture can then be used as the source texture of a RawImage UI object. So you can place that minimap window on a canvas, just like any other UI object.

Which camera renders what can be controlled via layers. Or alternatively you can just try to design the spacial layout of your scene in a way that the two cameras and the things they render never get close enough to each other for anything to ever appear in the field of view of the wrong camera. Usually I would not advise that (because you never know how your scene might evolve), but your use-case sounds simple enough that it could work.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.