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
0
Question by NinjaRubberBand · Jun 16, 2014 at 12:09 PM · playerprefsapplicationcase

saving numbers with PlayerPrefs

So im testing some app making in unity (I know unity isnt for apps). The app is very simple. There is 4 smileys. A mad smiley, a "okay" smiley, a "good smiley, and a "very good" smiley. Its like judgemnet app. And when you press on of the smileys, it gives 1 point to that smiley. And then you can see the statistics like this:

Mad: 8 Okay: 3 Good: 20 Very good: 34

But im having problems with saving the numbers. I have done it before with highscores, but its a little different. I know i need to use PlayerPrefs but i dont know how to use it in this case. What i want is that there is a "saved number". And when i press the smiley the "saved number" gets 1+. And i then can go out of the app and open it again, and its still 1.

Here is my code: #pragma strict

 var rigtiggodKlik = 0; //How many voted on this smiely.
 
 function Start () {
 
 }
 
 function Update () 
 {
 
 
 }
 
 
 function OnMouseDown () {
 rigtiggodKlik++;
 Application.LoadLevel("Takforstemme"); //Loading a new level that says: "Thanks for voting!".

 }


So i want the "rigtiggodKlik" to be saved.

Comment
Add comment · Show 1
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 NinjaRubberBand · Jun 16, 2014 at 01:14 PM 0
Share

bump bumpp

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by HarshadK · Jun 16, 2014 at 01:18 PM

Psuedo-code:

 function OnMouseDown () {
 
 // Get value of your rigtiggodKlik from your Playerprefs using Playerprefs.GetInt("rigtiggodKlik");
 
 // Add one and set value of rigtiggodKlik using Playerprefs using Playerprefs.SetInt("rigtiggodKlik", rigtiggodKlik++);
 
 // Save your Playerprefs using Playerprefs.save
 
 Application.LoadLevel("Takforstemme"); //Loading a new level that says: "Thanks for voting!".
 }

EDIT: Updated to reflect the updated code derived from the code of OP.

 var rigtiggodKlik : int = 0; //How many voted on this smiely.
 var rigtigGod : int = PlayerPrefs.GetInt("rigtiggodKlik", 0);
 
 function Start () {
 }
 
 function Update () 
 {
 }
 
 function OnMouseDown () {
     Debug.Log("MouseDown");
     rigtiggodKlik = PlayerPrefs.GetInt("rigtiggodKlik"); 
     PlayerPrefs.SetInt("rigtiggodKlik", rigtiggodKlik++);
     PlayerPrefs.Save();
     Application.LoadLevel("Takforstemme"); //Loading a new level that says: "Thanks for voting!".
 }
Comment
Add comment · Show 8 · 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 NinjaRubberBand · Jun 16, 2014 at 01:33 PM 0
Share

So according to what i saw in the code, i got it to this: #pragma strict

 var rigtiggod$$anonymous$$lik = 0; //How many voted on this smiely.
 var rigtigGod : int = PlayerPrefs.GetInt("rigtiggod$$anonymous$$lik", 0);
 
 function Start () {
 
 }
 
 function Update () 
 {
 
 
 }
 
 
 
 
 
 
 function On$$anonymous$$ouseDown () {
  Debug.Log("$$anonymous$$ouseDown");
 PlayerPrefs.GetInt("rigtiggod$$anonymous$$lik"); 
 PlayerPrefs.SetInt("rigtiggod$$anonymous$$lik", rigtiggod$$anonymous$$lik++);
 PlayerPrefs.Save();
 Application.LoadLevel("Takforstemme"); //Loading a new level that says: "Thanks for voting!".
 }

But it does not work.

avatar image Landern · Jun 16, 2014 at 01:41 PM 1
Share
 PlayerPrefs.GetInt("rigtiggod$$anonymous$$lik"); 
 
 //This just gets the value out of the playerprefs, you need to stuff it into a variable:
 
 rigtiggod$$anonymous$$lik = PlayerPrefs.GetInt("rigtiggod$$anonymous$$lik"); 
avatar image HarshadK · Jun 16, 2014 at 01:45 PM 1
Share

@Landern that's quite a shame for me. How did I miss that?

avatar image Landern · Jun 16, 2014 at 01:46 PM 1
Share

@Harshad$$anonymous$$, probably because you're trying to answer all the questions :)

avatar image HarshadK · Jun 16, 2014 at 01:52 PM 1
Share

@Landern Thank you, your highness! :-)

Show more comments
avatar image
1

Answer by Landern · Jun 16, 2014 at 01:18 PM

 PlayerPrefs.SetInt("WhatEverYouWantToCallItInternally", rigtiggodKlik);
 PlayerPrefs.Save();


then when you load

 var rigtiggodKlik:int = PlayerPrefs.GetInt("WhatEverYouWantToCallItInternally", 0); // the zero here is the default if the key isn't found.

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

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PlayerPrefs from One App to Another. 1 Answer

PlayerPref/PlayerPrefsX why not able to store boolean values? 1 Answer

Storing in PlayerPref based on timer 1 Answer

how autosave for reduce blood 1 Answer

Saving with PlayerPrefs? How it works? 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