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 /
  • Help Room /
avatar image
0
Question by Omega2077 · Nov 05, 2015 at 06:48 AM · playerprefsscriptingbasicshighscorespersistentdatapath

How do I incorporate the PlayerPrefs.Save so that it writes all the modified data to disk. Note I am very new to C# and thank you all in advance

using UnityEngine; using System.Collections;

public class Score : MonoBehaviour {

 static int score = 0;
 static int highScore = 0;


 static public void AddPoint() {
     score++;

     if(score > highScore) {
         highScore = score;
     }
 }

 void Start() {
     highScore = PlayerPrefs.GetInt("highScore", 0);
 }

 void OnDestroy() {
     PlayerPrefs.SetInt ("highScore", highScore);
 }

 void ExitGame() {
     highScore = PlayerPrefs.Save (PlayerPrefs.SetInt ("highscore"));
 
 }

 void Update () {
     GetComponent<GUIText> ().text = "Score: " + score + "\nHigh Score: " + highScore;
 }

}

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 saud_ahmed020 · Nov 05, 2015 at 06:51 AM 0
Share

@Omega2077 Try it :) http://docs.unity3d.com/ScriptReference/PlayerPrefs.html

1) http://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html 2) http://docs.unity3d.com/ScriptReference/PlayerPrefs.GetInt.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Levithan6785 · Nov 05, 2015 at 06:47 PM

This is very simple to do actually.

When loading the scores:

 void Awake()
 {
    highScore =  PlayerPrefs.GetInt("name"); //Grabs an integer in playerPrefs by the name of "name"
 }

So set an integer to be saved

 PlayerPrefs.SetInt("name", score); //Sets an integer to the playerPref named "name". Then score is the value you are saving
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
0
Wiki

Answer by Omega2077 · Nov 06, 2015 at 04:07 AM

Thank you

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 Omega2077 · Nov 07, 2015 at 11:12 AM 0
Share

Hi again I did try that code but it did not work tried a few other things but still no success, I could really use more ideas on how to do this.

What I need to know is how to SetInt and GetInt through persistence data, does anyone know how?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Hi Everyone i need to get the high score but i get last score player achieve it ,Hi Everyone i want to get The High Score of level but i get last Score Can you help me 1 Answer

how do i store highscore locally C# (SIMPLE) 3 Answers

Highscore not working 0 Answers

Help making a high score with player prefs/displaying it 1 Answer

How do I access playerprefs from another script? 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