Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This is my current code, it only work into unity, when i test it in an Android Device it don't save the variable

public class Click : MonoBehaviour{

public UnityEngine.UI.Text proiettiliTotali;
public UnityEngine.UI.Text bpc;
public float proiettili = 0.00f;

void OnEnable(){
        proiettili = PlayerPrefs.GetFloat("Player Score");
}

// Update is called once per frame
void Update () {
    proiettiliTotali.text = ConvertiroreProiettili.Instance.GetCurrencyInString(proiettili, false, false);
    bpc.text = ConvertiroreProiettili.Instance.GetCurrencyInString (proiettiliOgniClick, false, true);
}

public void Clicked () {
    proiettili += proiettiliOgniClick;
}

void OnDisable(){

    PlayerPrefs.SetFloat("Player Score", proiettili);
    PlayerPrefs.Save ();
    Debug.Log (proiettili);
}
share|improve this question
3  
One caution is that PlayerPrefs storage is not secure - the file can be viewed and modified as plaintext by an outside program. The Unity team advises against using this method to store information someone might want to hack, like scores, unlock progress, or in-game currencies. It's intended for preference information, like controls & sound/music settings, things the player can freely modify in-game anyway. – DMGregory May 4 at 21:22

PlayerPrefs creates on file on the disk of the device the app is used on, so it will not save between editor, and device. Other then that your code seems fine, I have noticed that if you build to your device on each test, that sometimes you lose your PlayerPrefs.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.