//Setting value
PlayerPrefs.SetInt("Score", currentScore);
PlayerPrefs.SetInt("HighScore1", currentScore);
PlayerPrefs.SetString("HighScore1Name", currentPlayerName);
//Getting values
highScore1 = PlayerPrefs.GetInt("HighScore1");
highScore1Name = PlayerPrefs.GetString("HighScore1Name", "N/A");
2. 파일을 이용한 저장(Serializer/Deserializer)
유니티는 Application.persistentDataPath 경로를 이용해서 사용자 데이터를
저장하고 불러올 수 있습니다.
void SaveScores()
{
//Get a binary formatter
var b = new BinaryFormatter();
//Create a file
var f = File.Create(Application.persistentDataPath + "/highscores.dat");
//Save the scores
b.Serialize(f, highScores);
f.Close();
}
void Start()
{
//If not blank then load it
if(File.Exists(Application.persistentDataPath + "/highscores.dat"))
{
//Binary formatter for loading back
var b = new BinaryFormatter();
//Get the file
var f = File.Open(Application.persistentDataPath + "/highscores.dat", FileMode.Open);
//Load back the scores
highScores = (List<ScoreEntry>)b.Deserialize(f);
f.Close();
}
}
댓글 없음:
댓글 쓰기