So i found this script on the internet
StreamWriter writer = new StreamWriter("MyFile.dat");
writer.WriteLine("Hello");
writer.WriteLine("World");
I modified it to my script and added the using system.io;
but where does it write to? I have the script running with no errors but i dont 100% know if it works because i can see where it saves to on a persons computer, i wanted to be able to choose the directory but if i cant well, that kind of sucks. Id imagine it being possible to choose but i dont 100% know yet.
READ BELOW AT THE COMMENTS
EDIT
I posted an answer on a different post telling them to go to here so this is an example i use this in…
using UnityEngine;
using System.Collections;
using System.IO;
public class CharacterSelection : MonoBehaviour {
public string CharacterName = "No Character Created!";
public string psi;
public string PVPTeam;
public string Level;
public string gold;
public string EXP;
public string LvlUP;
public string angel;
public string demon;
public string button001;
public int SelectCharacters = 1;
public int CreateCharacters = 0;
// Use this for initialization
void Start () {
PlayerController pc = (PlayerController)GetComponent("PlayerController");
CharacterName = pc.Name;
Level = pc.Level.ToString();
PVPTeam = pc.PVPTEAM;
psi = pc.PSI;
gold = pc.Gold.ToString();
EXP = pc.EXP.ToString();
LvlUP = pc.LvlUP.ToString();
angel = pc.isAngel.ToString();
demon = pc.isDemon.ToString();
}
// Update is called once per frame
void Update () {
PlayerController pc = (PlayerController)GetComponent("PlayerController");
if (SelectCharacters == 1)
{
button001 = "Create Character";
}
else
{
button001 = "Cancel";
}
ReadData();
WriteData();
}
void OnGUI()
{
Select();
Create();
if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 50, 150, 25), button001))
{
if (button001 == "Create Character")
{
SelectCharacters = 0;
CreateCharacters = 1;
}
else
{
SelectCharacters = 1;
CreateCharacters = 0;
}
}
}
public void Select()
{
if (SelectCharacters == 1)
{
GUI.Button(new Rect(10, 100, 10, 10), "<");
GUI.Button(new Rect(250, 100, 10, 10), ">");
if (GUI.Button(new Rect(30, 100, 200, 25), CharacterName))
{
}
}
}
public void Create()
{
Login l = (Login)GetComponent("Login");
if (CreateCharacters == 1)
{
GUI.Label(new Rect(10, 10, 200, 25), "Name: ");
CharacterName = GUI.TextField(new Rect(50, 10, 125, 25), CharacterName);
if (GUI.Button(new Rect(10, 40, 200, 25), "Create Character"))
{
StreamWriter writer = new StreamWriter(Application.dataPath + "Users/" + l.username + CharacterName + ".dat");
writer.WriteLine(CharacterName);
SelectCharacters = 1;
CreateCharacters = 0;
}
}
}
public void ReadData()
{
PlayerController pc = (PlayerController)GetComponent("PlayerController");
Login l = (Login)GetComponent("Login");
StreamReader reader = new StreamReader(Application.dataPath + "Users/" + l.username + CharacterName + ".dat");
string strAllFile = reader.ReadToEnd().Replace("
“, "
“).Replace(”
\r”, "
");
string arrLines = strAllFile.Split(new char { ’
’ });
CharacterName = arrLines[0];
Level = arrLines[1];
EXP = arrLines[2];
gold = arrLines[3];
LvlUP = arrLines[4];
psi = arrLines[5];
PVPTeam = arrLines[6];
angel = arrLines[7];
demon = arrLines[8];
}
public void WriteData()
{
PlayerController pc = (PlayerController)GetComponent("PlayerController");
Login l = (Login)GetComponent("Login");
StreamWriter writer = new StreamWriter(Application.dataPath + "Users/" + l.username + CharacterName + ".dat");
writer.WriteLine(pc.Name);
writer.WriteLine(pc.Level);
writer.WriteLine(pc.EXP);
writer.WriteLine(pc.Gold);
writer.WriteLine(pc.LvlUP);
writer.WriteLine(pc.PSI);
writer.WriteLine(pc.PVPTEAM);
writer.WriteLine(pc.isAngel);
writer.WriteLine(pc.isDemon);
}
}