In the Unity itself, when I start the game, everything is normal saves, and when compiled in .exe, then does not save anywhere how to fix? To maintain already with a compiled game
using unityengine;
Using System.Collections;
Using System.io;
Public Class Getname: Monobehaviour {
Public String FileName = "";
Public Name Char;
Public String Playername;
// Use this for initialization
void start () {
FileName = "PlayerName.txt";
}
// Update IS Called Once Per Frame
Void Update () {
}
void ongui ()
{
Name namest = (name) char.getcomponent ("Name");
Gui.Label (NEW RECT (10, 110, 90, 100), "Your Name:");
Playername = Gui.TextField (New RECT (90, 110, 100, 20), PlayerName);
if (GUI.BUTTON (NEW RECT (200, 110, 50, 20), "Save"))
{
STREAMWRITER SW = New Streamwriter ("PlayerName.txt");
SW.WRITELINE (PlayerName);
SW.Close ();
}
}
}
Answer 1, Authority 100%
- try to catch an exception, it seems to me that it creates problems you.
Also, I advise you to useAppDomain
to process raw exceptions. - I do not advise you to save the file in this way, specify a more specific path to your file.
- Try downloading a file from the code and find out its way, it may be serialized in some other way. For example, in the
Temp
folder. - also use the class
application
and its propertiesPersistentDatapath
,streamingassetspath
.
Answer 2, Authority 67%
Possible problems while saving:
- Do you have an exception? If it happens – “catch” it and look for a solution for it.
- is saved, but another place. Try to specify the full path to the desired directory for the test and make sure whether it is saved to it (prevail to make it a record in this directory).
- Features of the place of conservation for different platforms. Try to specify also Application.persistentDataPath in the save path.
Answer 3, Authority 33%
Try saving the file elsewhere. For example
streamwriter SW = New Streamwriter (@ "C: /PlayerName.txt"); // for PC
either so for various platforms (Win, MacOS, IOS, Android, etc.)
STREAMWRITER SW = New Streamwriter (Application.persistentDatapath + @ "/ PlayerName.txt");
The last option is optimal and correct if you calculate the various platforms to collect the project.
In general, here.