• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DubstepDragon · Jun 12, 2013 at 08:16 PM · playerprefsmonodevelopint

Saving an int via PlayerPrefs...

I have a value of gold that the player collected stored in an integer. However, how would I save this using PlayerPrefs(in C#)?

Thanks in advance!

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image clunk47 · Jul 19, 2013 at 05:19 PM 1
Share

Voted you back UP to zero, not sure why someone voted u down lol

avatar image DubstepDragon · Jul 22, 2013 at 06:13 PM 2
Share

Oh thx! I dunno, retards on this network, say stuff like "YOU N00B AS$$anonymous$$ING FOR SCRIPTS!" when all I am doing is asking for assistance...

avatar image clunk47 · Jul 22, 2013 at 06:18 PM 1
Share

Well you didn't just ask for a script like some people. If someone gets on here and says "Give me a script to do this", I usually bitch at them haha XD

avatar image DubstepDragon · Jul 22, 2013 at 06:28 PM 1
Share

Yeah, but come now, all I do is ask for technical assistance, and they go all "HURR DURR SHUN THE SCRIPT-AS$$anonymous$$ER DERP LOL #WEWANNAABUSEOURPOWERS #YOLOSWAG BWAHAHAHAHA!" it's really frustrating at times to work with people doing that. I mean I was practically screaming at an admin for closing my question when I was working under a deadline... Not cool...

avatar image DubstepDragon · Jul 22, 2013 at 07:43 PM 2
Share

Crap, looks like I uninstalled skype... I will add you as soon as it finishes installing. Who knows, maybe from time to time I will need assistance! Thanks dude!

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by clunk47 · Jun 12, 2013 at 08:24 PM

 PlayerPrefs.SetInt("Gold", goldAmount);

Check out the DOCS.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
5

Answer by Lukas H · Jun 13, 2013 at 12:42 PM

And to retrieve it again do something like:

 private int goldAmount = 0;
 
 void Start()
 {
    goldAmount = PlayerPrefs.GetInt("Gold");
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DubstepDragon · Jul 22, 2013 at 06:14 PM 2
Share

Sweet, thx man!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Is this the best way to do an AutoParallax Background ? 1 Answer

How to tell if an int is even 2 Answers

setting max varible value 5 Answers

PlayerPrefs for unlocking items 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges