using System.IO;
書き込み
StreamWriter writer = new StreamWriter(パス);
writer.Write(データ);
writer.Flush();
writer.Close();
読み込み
StreamReader reader = new StreamReader(パス);
データ = reader.ReadToEnd();
reader.Close();
※データは文字列型
プログラム例
using UnityEngine;
using System.IO;
public class Save : MonoBehaviour
{
int high_score = 0;
string path = "";
void Start()
{
path = Application.dataPath + "/save.txt";
}
//書き込み
public void Write()
{
StreamWriter writer = new StreamWriter(path);
string score = high_score.ToString();
writer.Write(score);
writer.Flush();
writer.Close();
}
//読み込み
public void Read()
{
string score = "";
StreamReader reader = new StreamReader(path);
score = reader.ReadToEnd();
reader.Close();
high_score = int.Parse(score);
}
}