Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Dilanwizzy · Oct 30, 2015 at 09:08 PM · script.playerprefsscore

keep adding to playerprefs

I am making a game similar to something like temple run but like a platform type. I'm 90% finished on my project but i need help with the coin. I know how to use playerprefs to store data but i don't how to add to it. what i mean by this is if the user gets like 300 coin in the first ran, it will display in the main menu. But then if the user gets like 200 in the second run it should add 200 to 300 and in the main menu it should display 500. And so on..

Comment
Add comment
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

1 Reply

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

Answer by HenryStrattonFW · Oct 31, 2015 at 12:36 AM

All you have to do for this, is read out the previous value from prefs, add to it, and then write it again. For example.

 int lTotalCoins = PlayerPrefs.GetInt("TotalCoins", 0);
 lTotalCoins += lCoinsCollectedThisRun;
 PlayerPrefs.SetInt("TotalCoins", lTotalCoins);
 
Comment
Add comment · Show 3 · 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 Dilanwizzy · Nov 02, 2015 at 07:23 PM 0
Share

Thank you for the help, now I can continue :) also this can help me when uses want to buy coins

avatar image Dilanwizzy · Nov 02, 2015 at 07:31 PM 0
Share

But I have a problem. The code works fine but when I quit the game and play it again, what ever amount of coins I got the last run it adds to it. For example I have 250 coins. I play the game and I get 20 coins, it adds 20 to 250 so 270 coins. I decide to close the game. Later when I opened it my coin count went up to 290. I close it again and reopen the game, now the coin count is on 310. I can keep opening and closing the game and it will add 20 every time without me even playing.. Any help?

avatar image Dilanwizzy · Nov 02, 2015 at 07:35 PM 0
Share

No worries I fixed it and its working fine now

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Guide in ArrayPrefs or PlayerPrefx? 1 Answer

DontDestroyOnLoad reset the gameobject 1 Answer

PlayerPrefs Highscore problem 1 Answer

calculate playerprefs and display 1 Answer

Playerprefs When the value I set is zero, there is a 2x increase in the part I get. when i close and reopen the game it only shows the last value. How can ı solve these? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges