Quantcast
Viewing all articles
Browse latest Browse all 100

Weapon store using playerprefs does not retain stored information.

I'musing playerprefs to store and int value under the name of 'wep1', and have it initially set to 0. when purchasing the gun, the int value should become 1. The point of the shop is to allow the user to switch between guns as they choose in the store after a one time purchase, because if the int value in the playerprefs is supposed to be initially purchased if the 'wep1' value is set to one. The problem is that it doesn't seem to be rewriting the valueto tell the playerprefs that the value is now 1, resulting in the gun having to be rebought over and over again, which is problematic. var gun : String; var purchased : boolean = false; var cost : int = 0; var money : int = 0; var ID : int; function Update(){ money = PlayerPrefs.GetInt("$$$"); } function OnMouseDown(){ if(purchased == false){ if(PlayerPrefs.GetInt("$$$") >= cost){ money -= cost; PlayerPrefs.SetInt("$$$", money); purchased = true; if(ID == 1){ PlayerPrefs.SetInt("wep1", 1); } } if(purchased == true){ PlayerPrefs.SetString("PRI", gun); } } } function start(){ if(ID == 1){ if(PlayerPrefs.GetInt("wep1") == 1){ purchased = true; }} } This is the reduced script (As the game has 27 total weapons), I'm wondering if anyone can tell me what is causing the error.

Viewing all articles
Browse latest Browse all 100

Trending Articles