var score:int; function Start(){ score = PlayerPrefs.GetInt("Player HighScore"); } function OnGUI () { if (GUI.Button (Rect (10,10,150,100), "high score : " + score)){ Application.LoadLevel("start"); } if (GUI.Button (Rect (210,10,150,100), "reset")){ score = 0; saveScore(); } if (GUI.Button (Rect (410,10,150,100), "set 123")){ score = 123; saveScore(); } } function saveScore(){ PlayerPrefs.SetInt("Player HighScore", score); PlayerPrefs.Save(); }
実行して、値を123にセットし、停止。次回開始時にはhigh score : 123 と表示できた。 リファレンス http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html