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;
- public class TextField : MonoBehaviour {
- public InputField _text;
- public string text;
- public bool stream;
- void Start()
- {
- stream = true;
- _text = GetComponent<InputField>();
- LoadText();
- }
- void Update()
- {
- if (stream == false)
- {
- text = _text.text;
- }
- else if (stream == true)
- {
- _text.text = text;
- }
- }
- public void SaveText()
- {
- if (!Directory.Exists(Application.dataPath + "/Saves"))
- Directory.CreateDirectory(Application.dataPath + "/Saves");
- StreamWriter txt = new StreamWriter(Application.dataPath + "/Saves/savetxt.lg");
- txt.WriteLine(text);
- txt.Close();
- Debug.Log("SaveText");
- }
- void LoadText()
- {
- StreamReader streamreader = new StreamReader(Application.dataPath + "/Saves/savetxt.lg");
- if (streamreader != null)
- {
- while (!streamreader.EndOfStream)
- {
- _text.text = streamreader.ReadLine();
- }
- }
- stream = false;
- Debug.Log("LoadText");
- }
- public void Exit()
- {
- Application.Quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement