Saving game information to text

I’ve got a script working in editor to save my scene information to a text file (prefs aren’t usable here).

The script doesn’t work on android.

I’m basically using Streamwriter to append text to a new .txt file. Every save is a new text file. At the menu screen I use System.IO.ReadAllText and Regex the hell out of it to get what I need. At present, I don’t see any files at the menu scene after a save.

Is there something wrong with my approach for android (or IOS, in case I want to work with that later)?

Are you using Application.persistentDataPath?
Unity - Scripting API: Application.persistentDataPath ?

No and you’re a damn genius. Thank you. I had hoped it was something as simple as this. I’ll try it out soon and I hope this will fix my problem (but it certainly sounds promising).

I can save the text file, but I’m having an issue with some code regarding finding all of the files in the directory.

void OnGUI()
	{
		GUILayout.BeginArea(new Rect(Screen.width*.5f,Screen.height*.25f,Screen.width*.5f,Screen.height*.7f));
		DirectoryInfo dir = new DirectoryInfo(Application.persistentDataPath+"/files");


		GUILayout.Label("Saved maps");


			foreach (var f in dir.GetFiles("*.dm"))
			{

				string del = ",";
				string text = System.IO.File.ReadAllText(f.FullName);
				string[] lines = Regex.Split(text, "\r\n");

				string[] cells = Regex.Split(lines[lines.Length -2], del);

				if(GUILayout.Button (cells[1]+":"+cells[0]+"  "+cells[4], GUILayout.Width(Screen.width*.499f), GUILayout.Height(Screen.height*.06f)))
				    {
					Debug.Log(cells[1]+" by "+cells[0]+"  "+cells[4]+" loading.");
					PlayerPrefs.SetFloat ("xS", float.Parse(cells[2]));
					PlayerPrefs.SetFloat ("yS", float.Parse (cells[3]));
					PlayerPrefs.SetString ("Load", "true");
					PlayerPrefs.SetString("File", f.FullName);
					Application.LoadLevel("Table");
					}
			}
				


		GUILayout.EndArea();
	}

Does System.IO work on android? This code works flawlessly in editor (after changing the path).

Additionally, I don’t like searching the file system on every OnGUI call, but I’m not sure how else to do it.

It should work. Does adb logcat complain something?

I’m a little new to debugging for android, I probably should have checked logcat earlier.

It pointed me to a problem I have with my file loading script (Array out of index). Thanks for simply saying logcat though since I had simply forgotten about it