Text Assets – loading from the local files

Another method to load in text data is externally from the project, that is, from files on the local hard drive. Text Data loaded in this way is read into the project dynamically from script, not necessarily at scene startup, but whenever you execute the necessary code. This means that for longer text files that involve heavy processing, lag becomes a serious consideration. In general, therefore, it is best to prefer statically loaded Text Assets to dynamic forms. For any dynamic assets, I recommend that you load and process them at scene startup to avoid in-game lagging, as shown in the following code sample 6-26:

 using UnityEngine;
 using System.Collections;
 using System.IO; //Function to load text ...

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.