Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.IO;
  5. using System.Text;
  6.  
  7. public class TextField : MonoBehaviour {
  8. public Text _text;
  9. public string text;
  10. void Start()
  11. {
  12. LoadText();
  13. }
  14. public void Field(string text)
  15. {
  16. _text = text;
  17. }
  18. public void SaveText()
  19. {
  20. if (!Directory.Exists(Application.dataPath + "/Saves"))
  21. {
  22. Directory.CreateDirectory(Application.dataPath + "/Saves");
  23. }
  24. FileStream fstext = new FileStream(Application.dataPath + "/Saves/save.txt", FileMode.Create);
  25. StreamWriter writer = new StreamWriter(fstext);
  26. writer.Write(text);
  27. writer.Close();
  28. fstext.Close();
  29. }
  30. void LoadText()
  31. {
  32. if (File.Exists(Application.dataPath + "/Saves/save.txt"))
  33. {
  34. FileStream fstext = new FileStream(Application.dataPath + "/Saves/save.txt", FileMode.Open);
  35. StreamReader reader = new StreamReader(fstext);
  36. try
  37. {
  38. reader.Read(text);
  39. reader.Close();
  40. }
  41. catch (System.Exception)
  42. {
  43.  
  44. }
  45. finally
  46. {
  47. fstext.Close();
  48. }
  49. }
  50. else
  51. {
  52.  
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement