0
\$\begingroup\$

I have a question about playerprefs on my android mobile game not initializing properly. I have already pre-set my playerprefs data on a variable with a value of 3. In my play mode on unity the value is showing 3 through the textmesh that I have it scripted on. But when I install and test it on my android mobile device it is 0. can someone help how to properly initialize my playerprefs data to the right value on android platform?

 public static Game GM;
 int maxAntiBody;
 public TextMeshProUGUI antibodyTexMesh;

void Start () {
    if (GM == null)
    {
        GM = this;
    }
 maxAntiBody = PlayerPrefs.GetInt("MaxAntiBody");
 antibodyTexMesh.text = maxAntibody.toString();
}

void Update () {
debugging();
}

//I use this method for setting or resetting my desired value for the playerprefs data I'm working with. In this case I choose 3 as a value.
void debugging() {
    if (Input.GetKeyDown(KeyCode.M))
    {

        PlayerPrefs.SetInt("MaxAntiBody", plus++);
        Debug.Log("max anti body value is : " + PlayerPrefs.GetInt("MaxAntiBody"));
    }
    else if (Input.GetKeyDown(KeyCode.R))
    {
        plus = 0;
        PlayerPrefs.SetInt("MaxAntiBody", plus);
        Debug.Log("max anti body is now reseted to : " + PlayerPrefs.GetInt("MaxAntiBody"));
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ I'm not sure, but do you expect to be able to write something to PlayerPrefs on your PC and then read that value when you run the game on your Android device? Or do you want that variable to always start with 3 when the game is first run on a new device? \$\endgroup\$
    – Philipp
    Commented May 11, 2020 at 8:17
  • \$\begingroup\$ its the first one : ) \$\endgroup\$
    – Ryan Cat
    Commented May 11, 2020 at 8:23
  • \$\begingroup\$ How is that supposed to be technically possible? They are two different devices which don't know anything about each other's existence. \$\endgroup\$
    – Philipp
    Commented May 11, 2020 at 8:25

0

You must log in to answer this question.

Browse other questions tagged .