- Home /
textasset and how to use them
So i was making my first game in unity. I was using a .txt file to store dialogues, I have script that reads it line by line and add to list so I can use them later.But apparently the way I was reading that text file doesn't work after building the application. I've read that I need to use textasset, however i could't find any clear informations on how to use that function. Here is code I was using:
struct DialoguLine
{
public string name;
public string content;
public string[] options;
public DialoguLine(string Name, string Content)
{
name = Name;
content = Content;
options = new string[0];
}
}
List<DialoguLine> lines;
void Start () {
string file = "Assets/data/dialogue.txt";
lines = new List<DialoguLine>();
loaddialogue(file);
}
// Update is called once per frame
void Update () {
}
void loaddialogue(string filename)
{
string line;
StreamReader page = new StreamReader(filename);
using (page)
{
do
{
line = page.ReadLine();
if (line != null)
{
string[] lineContent = line.Split(';');
if (lineContent[0] == "player")
{
DialoguLine nextline;
nextline.name = lineContent[0];
nextline.content = "";
nextline.options = new string[lineContent.Length-1];
for (int i = 1; i < lineContent.Length; i++)
{
nextline.options[i - 1] = lineContent[i];
}
lines.Add(nextline);
}
else
{
DialoguLine nextline;
nextline.name = lineContent[0];
nextline.content = lineContent[1];
nextline.options = new string[0];
lines.Add(nextline);
}
}
} while (line != null);
page.Close();
}
}
So here comes my question, how can I add this txt file as textAsset(this question may seem stupid to you but I honestly don't know and was unable to find any explanation) and how to change this code to make it work? BTW Sorry for bad english
Your answer
Follow this Question
Related Questions
Change contents of TextAsset 2 Answers
Text file read, random quote C# 1 Answer
Assign public variables in design time... through code! 0 Answers
How am I accessing my Dictionary wrong? 1 Answer
TextAsset vs StreamReader 2 Answers