반응형
- 코드 작성
using UnityEngine;
using System.IO;
public class FileSaveLoad : MonoBehaviour
{
private string savePath;
private void Start()
{
savePath = Application.persistentDataPath + "/save.txt";
}
private void SaveData(string data) //저장하기
{
StreamWriter writer = new StreamWriter(savePath);
writer.Write(data);
writer.Close();
Debug.Log("Data saved to: " + savePath);
}
private string LoadData() //불러오기
{
string data = "";
if (File.Exists(savePath))
{
StreamReader reader = new StreamReader(savePath);
data = reader.ReadToEnd();
reader.Close();
Debug.Log("Data loaded from: " + savePath);
}
else
{
Debug.Log("Save file not found!");
}
return data;
}
private void ExampleUsage()
{
string dataToSave = "Hello, World!";
SaveData(dataToSave);
string loadedData = LoadData();
Debug.Log("Loaded Data: " + loadedData);
}
}
반응형