Why is UnauthorizedAccessException ?
please help QAQ
private string filePath;
private bool fileExist;
static public string[] begining;
public int level;
public int health;
public int mana;
void Start()
{
CreateNewFile();
}
void CreateNewFile()
{
filePath = Application.dataPath + @"\data\playerdata";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
if (!File.Exists(filePath + @"\playerdata.txt"))
{
fileExist = false;
begining = new string[] { "1", "5", "10" };
System.IO.File.WriteAllLines(filePath + @"\playerdata.txt", begining);
}
else
{
fileExist = true;
begining = System.IO.File.ReadAllLines(filePath);
}
level = int.Parse(begining[0]);
health = int.Parse(begining[1]);
mana = int.Parse(begining[2]);
}
void Update()
{
}
}
Which platform? I guess under most platforms you don't have write access to the directory in Application.dataPath. Try Application.persistentDataPath ins$$anonymous$$d.
Answer by HenryStrattonFW · Feb 04, 2017 at 01:16 PM
For saving player data on device to files, you want to use Application.persistantDataPath instead of dataPath you should always have access to write to persistantDataPath
Your answer
Follow this Question
Related Questions
should i learn html and css to make a web pages becouse there now free web hosting sites 0 Answers
Problems with Xbox360 controler triggers 0 Answers
How to specify in the GetComponent method in colliders?! 2 Answers
is it possible to use multiple scenes as saveslots and if so how 0 Answers
How can you get dynamic textures and conflicting behaviours for a single game object? 0 Answers