Hi I am attempting to write a script to create a gui box with text in it that changes based on a keyboard click. I have got the basics up and running (its far from the finnished product). I am haveing an issue wuth this section of code.
void read_file()
{
TextReader tr = new StreamReader("Assets/test.txt");
conversation = tr.ReadLine();
tr.Close();
}
when I am running the script in unity it will locate the txt file and read the first line to the variable and then update my GUI element. but when I buiold the project and test it it does not work so I assume it cannot be located. I would appriciate any advice on this issue. Here is the full script I have coded so far if it helps for refrence.
using UnityEngine;
using System.Collections;
using System;
using System.IO;
public class convo : MonoBehaviour {
public string conversation;
// Use this for initialization
void Start () {
conversation = "Hello this is a test";
}
// Update is called once per frame
void Update () {
if (Input.GetKeyUp(KeyCode.E))
{
read_file();
}
}
void OnGUI()
{
GUI.Box(new Rect(10, 200, 500, 50), conversation);
}
void read_file()
{
TextReader tr = new StreamReader("Assets/test.txt");
conversation = tr.ReadLine();
tr.Close();
}
}
Thanks
Dave