- Home /
Question by
mohOsama · Jul 09, 2017 at 02:07 PM ·
playerprefssave datahighscores
PlayerPrefs not working with android
in my simple Game when i try to set the high score it works in unity editor and windows build but not in android build
#pragma strict
public var scoreTxt :GameObject ;
public var bestScoreTxt :GameObject ;
var currentBestScore ;
function Start () {
bestScoreTxt.GetComponent.<UI.Text>().text = PlayerPrefs.GetString("Best",scoreTxt.GetComponent.<UI.Text>().text) ;
var target : motoScript = GetComponent (motoScript) ;
bestScoreTxt.GetComponent.<UI.Text>().text = PlayerPrefs.GetString("Best");
if(float.Parse(scoreTxt.GetComponent.<UI.Text>().text) >=float.Parse(bestScoreTxt.GetComponent.<UI.Text>().text)){
bestScoreTxt.GetComponent.<UI.Text>().text = scoreTxt.GetComponent.<UI.Text>().text ;
PlayerPrefs.SetString("Best" ,bestScoreTxt.GetComponent.<UI.Text>().text ) ;
}
}
screenshot-2017-07-09-16-07-22.png
(71.8 kB)
Comment
Best Answer
Answer by mohOsama · Jul 10, 2017 at 12:53 AM
It Worked now when i changed "SetString" to "SetInt" here is the new code
#pragma strict
public var scoreTxt :GameObject ;
public var bestScoreTxt :GameObject ;
var currentBestScore ;
function Start () {
bestScoreTxt.GetComponent.<UI.Text>().text = PlayerPrefs.GetInt("Best",0).ToString() ;
var target : motoScript = GetComponent (motoScript) ;
bestScoreTxt.GetComponent.<UI.Text>().text = PlayerPrefs.GetInt("Best").ToString();
if(float.Parse(scoreTxt.GetComponent.<UI.Text>().text) >=float.Parse(bestScoreTxt.GetComponent.<UI.Text>().text)){
bestScoreTxt.GetComponent.<UI.Text>().text = scoreTxt.GetComponent.<UI.Text>().text ;
PlayerPrefs.SetInt("Best" , float.Parse(bestScoreTxt.GetComponent.<UI.Text>().text ) ) ;
}
}
Your answer
Follow this Question
Related Questions
High Score with player prefs confusion (JAVA) 0 Answers
Binary writer not saving game data on iOS builds 1 Answer
PlayerPrefs.GetString not saving past values 0 Answers
PlayerPref resets the value,PlayerPref displays the stored value and then resets it 1 Answer
Save Object Material Color ?? 1 Answer