- Home /
Figured it out.
PlayerPrefs.GetInt won't load when awake.
I have a strange problem where my PlayerPrefs.SetInt works and saves just fine, But when i try to load it with void awake or start, the value stays at 0 until something is added to it.
For example: If i have collected 20 items in my game and then reload the game, The item counter is 0 until i pick up another item and then it displays 21, despite the preference being loaded on awake/start.
If you guys have any idea of what's happening please let me know.
Sure, you probably did something wrong ...
Code?
To me that sounds like it's loading just fine, but you did not update the display of your counter.
Please asked more detailed questions. You force us to stab in the dark. This site is for clear and detailed questions that can be answered and not a game called "guess what my problem is".
So please edit your question
so this is basically whats going on in my script:
void Awake() {
points = PlayerPrefs.GetInt("Score");
}
void OnTriggerEnter(Collider other) {
if (other.tag == "point") {
points += 1;
Destroy(other.gameObject);
scoreText.text = ""+points;
}
if (other.tag == "Exit"){
PlayerPrefs.SetInt("Score", points);
PlayerPrefs.Save();
}
Never$$anonymous$$d. i just rebooted unity and it started working just fine, The value in the text was updated by another script which wasn't loading correctly. Thanks for your advice anyways.
Follow this Question
Related Questions
Loading error when using PlayerPrefs.GetInt with WebPlayer 2 Answers
PlayerPrefs for saving strings 1 Answer
Saving and loading game with PlayerPrefs 1 Answer
PlayerPrefs Question 0 Answers