Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Heratitan · Aug 08, 2010 at 07:51 PM · playerprefsscore

Is there a way to add one to playerprefs?

So, I am using playerprefs to keep track of the current score in my game and I need the score to go up by one every time a player touches an object. Usually with playerprefs you set it just as a constant number, for example:

PlayerPrefs.SetInt("Score", 1);

but that just sets the score always as one, and this doesn't work:

PlayerPrefs.SetInt("Score", ++);

Does anyone know how to just raise the score by one? Thanks.

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

2 Replies

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

Answer by Wolfram · Aug 08, 2010 at 07:54 PM

PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score")+1);

Not sure how fast these functions are, and if you really want to update that everytime. Usually you'd only want to store/read the prefs if you start/load a game, or save a game, or exit the app. In all other cases you are probably better off with a simple variable in one of your scripts.

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 fireDude67 · Dec 30, 2010 at 05:17 AM 0
Share

Why not ++PlayerPrefs.GetInt("Score")?

avatar image fireDude67 · Dec 30, 2010 at 05:18 AM 0
Share

I mean for the assignment part

avatar image Wolfram · Jan 04, 2011 at 12:22 PM 0
Share

GetInt() is a method, you cannot increment that, nor its return value.

avatar image
0
Best Answer

Answer by Eric5h5 · Aug 08, 2010 at 09:15 PM

Usually with playerprefs you set it just as a constant number

I think you would almost never do that. Usually you set it from a variable.

PlayerPrefs.SetInt("Score", playerScore);

That should answer the rest of the question.

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 Heratitan · Aug 08, 2010 at 10:22 PM 0
Share

That was just how I was doing a lot of my other settings.

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Is it necessary to create an Array() to show high scores in PlayerPref? 1 Answer

How many different scripts do I need to write to create a highscore system? 1 Answer

Where am I going wrong with these scripts? 1 Answer

What am I doing wrong with PlayerPrefs? 3 Answers


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