#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 ) ;
}
}
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
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 ) ) ;
}
}