- Home /
PlayerPrefs not working?
I recently made a script makes a text say the amount of gold that another script holds. I wanted it to save and load the gold variable. But for some reason, it won't work. Help?
var Gold : float = 0;
var me : GUIText;
var otherme : GUIText;
function Update () {
Gold = otherme.GetComponent(GoldAmount).Goldd;
me.text = "Total Cash : " + Gold;
PlayerPrefs.SetInt("GOOLD" , otherme.GetComponent(GoldAmount).Goldd);
PlayerPrefs.Save();
}
function Start () {
Gold = PlayerPrefs.GetInt("GOOLD");
}
You really don't want that stuff in Update. Update runs every single frame.
Is reading a value FRO$$anonymous$$ GUIText a good idea? I'd use an intermediate variable to store the values and only output to GUIText when you want to display the value.
Answer by kurotatsu · Aug 22, 2013 at 11:40 PM
I wrote this script for saving position, but maybe you can see how to set up for saving your gold(I would save it as an integer).
http://answers.unity3d.com/questions/250734/player-prefs-saving-position-script-assistance.html
Edit:
Did you realize it's a float at the top of your script and you are trying to save it as an integer?
Your answer
Follow this Question
Related Questions
Saving and loading game with PlayerPrefs 1 Answer
Cannot run anything in iOS. No errors! 0 Answers
What is the best way to save a scene and load it later? 0 Answers
Calling a variable from another class 2 Answers
PlayerPrefs Question 0 Answers