2

I'm trying to create a top-down map in Unity2D, this map will act as an ocean that a 1 tile sized boat will drive across. I want to be able to generate this map programmatically by going through the grid to create shallow areas, spawn things, etc.

I've been reading it's not good practice to create game objects for each tile as there's so many. You can use object pooling but that sounds harder to manage. I've read that using a mesh map is the best way but no one follows up with the best way to implement it. Any clues to push me in the right direction?

DasBeasto
  • 628
  • 1
  • 7
  • 13

1 Answers1

1

UPDATE: As of Unity 2017.2, Unity now comes with an implementation of the mesh-grid-textured-quad approach. See the Unity documentation on Tilemap, and refer to the techdemo repository here for some examples of custom tiles.

Old Post------ There's a number of ways to do this sort of thing.

One is with Object Pooling. It's useful if you know you'll only show a small number of tiles to the player, but with a potentially huge map. A tutorial by the Unity team on how object poolers work can be found here.

The second way, if you plan to show potentially all of your tiles at a time, is to render them as individual quads on a single mesh. Basically you just swap out the texture mapped to the specific quad in the mesh. This can be more difficult to get started, but is very efficient for large maps that you always want visible (think civilization style). A tutorial on 2d maps built in this manner can be found here.

Stephan
  • 1,728
  • 11
  • 24