-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadWrite_TextFile.cs
More file actions
37 lines (31 loc) · 861 Bytes
/
ReadWrite_TextFile.cs
File metadata and controls
37 lines (31 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using UnityEngine;
using System.IO;
public class ReadWrite_TextFile : MonoBehaviour
{
[SerializeField] private string _Path = "";
[SerializeField] private string _FileName = "ExampleTextFile";
[Header("Example")]
[SerializeField] private string _Message = "Test Message";
void Start()
{
if (_Path == "")
{
_Path = "Assets/" + _FileName;
}
WriteTextFile();
ReadTextFile();
}
public void ReadTextFile()
{
StreamReader reader = new StreamReader(_Path + ".txt");
Debug.Log("Read Result: " + reader.ReadToEnd());
reader.Close();
}
public void WriteTextFile()
{
StreamWriter writer = new StreamWriter(_Path + ".txt", true);
writer.WriteLine(_Message);
writer.Close();
Debug.Log("Write Complete");
}
}