Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.IO;
  5. public class TextField : MonoBehaviour {
  6. public InputField _text;
  7. public string text;
  8. public bool stream;
  9. void Start()
  10. {
  11. stream = true;
  12. _text = GetComponent<InputField>();
  13. LoadText();
  14. }
  15. void Update()
  16. {
  17. if (stream == false)
  18. {
  19. text = _text.text;
  20. }
  21. else if (stream == true)
  22. {
  23. _text.text = text;
  24. }
  25. }
  26. public void SaveText()
  27. {
  28. if (!Directory.Exists(Application.dataPath + "/Saves"))
  29. Directory.CreateDirectory(Application.dataPath + "/Saves");
  30. StreamWriter txt = new StreamWriter(Application.dataPath + "/Saves/savetxt.lg");
  31. txt.WriteLine(text);
  32. txt.Close();
  33. Debug.Log("SaveText");
  34. }
  35. void LoadText()
  36. {
  37. StreamReader streamreader = new StreamReader(Application.dataPath + "/Saves/savetxt.lg");
  38. if (streamreader != null)
  39. {
  40. while (!streamreader.EndOfStream)
  41. {
  42. _text.text = streamreader.ReadLine();
  43. }
  44. }
  45. stream = false;
  46. Debug.Log("LoadText");
  47. }
  48. public void Exit()
  49. {
  50. Application.Quit();
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement