I’m trying to create a directory if it doesn’t exist:
public void Save ()
{
path = Application.streamingAssetsPath + "/Settings";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string finalPath = path + "/Camera_Settings.json";
string newSettings = JsonUtility.ToJson(cameraSettings);
File.WriteAllText(finalPath, newSettings);
Debug.Log("Saved!");
}
But I’m getting this error:
UnauthorizedAccessException: Access to the path ‘C:/Users/Igor/Desktop/MGS/Work/Projetos Unity 3D/Don’t Die/Assets/StreamingAssets/Settings/Camera_Settings.json’ is denied.
–
System.IO.FileStream…ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:259)
–
System.IO.FileStream…ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
–
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int)
–
System.IO.File.Create (System.String path, Int32 bufferSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:135)
–
System.IO.File.Create (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:130)
–
CameraFollow.Save () (at Assets/Scripts/Mechanics/CameraFollow.cs:91)
Is there any way to work around that? Please, answer as fast as possible. Thanks in advance.