Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.IO;
- using System.Text;
- public class TextField : MonoBehaviour {
- public Text _text;
- public string text;
- void Start()
- {
- LoadText();
- }
- public void Field(string text)
- {
- _text = text;
- }
- public void SaveText()
- {
- if (!Directory.Exists(Application.dataPath + "/Saves"))
- {
- Directory.CreateDirectory(Application.dataPath + "/Saves");
- }
- FileStream fstext = new FileStream(Application.dataPath + "/Saves/save.txt", FileMode.Create);
- StreamWriter writer = new StreamWriter(fstext);
- writer.Write(text);
- writer.Close();
- fstext.Close();
- }
- void LoadText()
- {
- if (File.Exists(Application.dataPath + "/Saves/save.txt"))
- {
- FileStream fstext = new FileStream(Application.dataPath + "/Saves/save.txt", FileMode.Open);
- StreamReader reader = new StreamReader(fstext);
- try
- {
- reader.Read(text);
- reader.Close();
- }
- catch (System.Exception)
- {
- }
- finally
- {
- fstext.Close();
- }
- }
- else
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement