Hello everybody, I read all questions, answers and guides about playerprefs that I could find, nothing helped me, so Im asking if there is another easy way to save data.
So you knew what Im trying to do here is my code:
var controlTexture : Texture2D;
var controlTexture1 : Texture2D;
var Score :int;
var Enemy : Transform;
var dist:int =1;
var lost = false;
var customSkin :GUISkin;
var highscore:int;
function start(){
highscore = PlayerPrefs.GetInt("HighscoreSTR");
}
function OnGUI () {
GUI.skin = customSkin;
GUI.Box(new Rect(10,10,150,45), Score.ToString());
GUI.Box(new Rect(10,60,150,45), highscore.ToString());
if (lost) {
GUI.Box(new Rect(Screen.width/2 -207 ,Screen.height/2 -95 ,420,200),"Well Played!");
if (GUI.Button (Rect (Screen.width/2 -200,Screen.height/2 + 50,150,50), controlTexture)){
Application.LoadLevel(1);
}
if (GUI.Button (Rect (Screen.width/2 +50,Screen.height/2 + 50,150,50), controlTexture1)){
Application.LoadLevel(0);
}
GUI.Label (Rect (Screen.width/2 -20 ,Screen.height/2 -50,500,500), Score.ToString());
}
}
function Update () {
if (Score >= highscore){
highscore = Score;
PlayerPrefs.SetInt("HighscoreSTR", highscore);
PlayerPrefs.Save();
}
dist = Vector3.Distance(Enemy.position, transform.position);
if (dist <=2){
lost = true;
}
if (lost){
Time.timeScale = 0;
}
else{
Time.timeScale = 1;
}
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
if (dist ==3){
Score = Score + 5 ;
}
if (dist ==4){
Score = Score + 3 ;
}
if (dist ==5){
Score = Score + 1 ;
}
}
}
}