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:
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:
//-------------------------------------------------- using UnityEngine; using System.Collections; //-------------------------------------------------- public class TextFileAccess : MonoBehaviour { //Reference a text file public TextAsset TextData = null; // Use this for initialization void Start () { //Display text in file Debug.Log (TextData...