This what I have written so far and it works fine in the editor but when I try it on my android phone it doesnt work. So what am I doing wrong?
using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
public class AndroidScoreSavingTest : MonoBehaviour {
string message;
string loadMessage = "Yeah working";
string data;
FileInfo f;
void Start()
{
f = new FileInfo(Application.dataPath + "\\" + "myFile.txt");
Screen.SetResolution(800, 600, true);
}
void OnGUI()
{
GUILayout.BeginArea(new Rect(0,0,500,500));
GUILayout.Label(message + " " + data);
if(GUILayout.Button("Save"))
{
if(!f.Exists)
{
message = "Creating File";
Save();
}
else
{
message = "Saving";
Save();
}
}
if(GUILayout.Button("Load"))
{
if(f.Exists)
{
Load();
}
else
{
message = "No File found";
}
}
GUILayout.EndArea();
}
void Save()
{
StreamWriter w;
if(!f.Exists)
{
w = f.CreateText();
}
else
{
f.Delete();
w = f.CreateText();
}
w.WriteLine(loadMessage);
w.Close();
}
void Load()
{
StreamReader r = File.OpenText(Application.dataPath + "\\" + "myFile.txt");
string info = r.ReadToEnd();
r.Close();
data = info;
}
}