how can I setup some values the first time when i Run the game for example I want my player to have 100$ the first time but I dont want him to have 100$ every time i open the app if he makes more or spend that’s his problem how can i do this ?
The title of your post is the answer you seek. Google “SetPlayerPrefs” and the solution will be right there.
You can set a default value for PlayerPrefs.For example:
int money = PlayerPrefs.GetInt("money", 100);
if i do like that for example i put this script on an gameobject this script won’t set my money every time i run on 100?
Not as long as “money” is set to something. So if you’ve done something like:
PlayerPrefs.SetInt("money", 42);
Then “money” will be defined and you’ll get its value when you do a GetInt.
So the default value is only assigned if the variable doesn’t exist in PlayerPrefs.
When you want to get variable of money you do that get int and that 100 means if there is no stored money it will set it to 100
Now when you want to save players amount of money you fo the set int function that pgj sent
And after you are done with setting all set int variables you do PlayerPrefs.Save();
(Dont do save function often. Just when needed because it is writing to file)
thank you a lot for everything it worked