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.

Loading game data from a text file map

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)

Get Unity 5.x Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.