Loading game data from a text file map
Rather than, for every level of a game, having to create and place every GameObject on the screen by hand, a better approach can be to create the text files of rows, and columns of characters, where each character corresponds to the type of GameObject that is to be created in the corresponding location. In this recipe, we'll use a text file and set of prefab sprites to display a graphical version of a text-data file for a screen from the classic game called NetHack.
Getting ready
In the 1362_10_08
folder, we have provided the following two files for this recipe:
level1.txt
(a text file, representing a level)absurd128.png
(a 128 x 128 sprite sheet for Nethack).
The level data came from the Nethack Wikipedia page, and the sprite sheet came from SourceForge:
Note that we also included a Unity package with all the prefabs set up, since...