Question by
Ippopotamo_G · Oct 20, 2020 at 11:44 AM ·
c#c# tutorial
Saving data in a txt file from Input Field button?
Hi, I have an inputfield and a button and I want to save in a txt file what I write in the inputfield after I click the button. I used Streamwriter but my code doesn't work.
public class Name : MonoBehaviour {
public InputField Name;
static void WriteString()
{
string path = "Assets/Resources/test.txt";
//Write some text to the test.txt file
StreamWriter writer = new StreamWriter(path, true);
writer.WriteLine("Test");
writer.Close();
//Re-import the file to update the reference in the editor
AssetDatabase.ImportAsset(path);
TextAsset asset = (TextAsset)Resources.Load("test");
//Print the text from the file
Debug.Log(asset.text);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613014159im_/https://answers.unity.com/themes/thub/images/avi.jpg)