Working with Text Data Assets

Throughout all examples so far, we've considered text directly stored in string objects, but you can also work with text files in Unity. Specifically, you can load in text from external sources. Here, I will demonstrate how.

Text Assets – static loading

The first method is to drag-and-drop a text file into a Unity project that imports the text asset. The file is imported as a TextAssets type, as shown here:

Text Assets – static loading

Importing text files into Unity as TextAssets

You can access the file and its text data from any script file by exposing a TextAsset public member, as shown in the following code sample 6-25:

//-------------------------------------------------- ...

Get Mastering Unity Scripting 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.