Computer documents path?

Hi!

I need to save a file to the players computer and I want it to save in Documents/Custom Levels. But I don’t know how I would get this to work. I also don’t know how I can get it to save on Mac since it appears to have a different path then Windows. But I still need help with Windows.

If you know these paths, please tell me!

Thanks

In the top of your file put:

import System.Environment;

Then try this:

var DocumentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
Debug.Log(DocumentsPath);

NOTE: The above is javascript

C#:

using System.Environment;

String DocumentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
Debug.Log(DocumentsPath);

Doing a short search I could find this code from Apache in Unity forums:

string path = "";

if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) {
    path = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
} else {
    path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
} // if

return path;

And combining it with this link from MSDN you can have it to write to My Documents in Windows and to Personal in Mac.

string path = "";

if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) {
    path = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
} else {
    path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
} // if

return path;