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 robbos729 · Jul 23, 2019 at 09:14 PM · textplayerprefshighscores

player prefs highscore

i have the highscore for my game sorted out but there is a catch. i have 2 modes and the high score in gamemode 1 is the same as 2 and vice versa. how can i fix this? I have the code and also in gamemode 1 i have the highscore text object called highscore compared to bestScore as i was trying to fix it.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class RushHighScore : MonoBehaviour
 {
     public int score = 0;
     public int bestScore = 0;
 
     private void Start()
     {
         bestScore = PlayerPrefs.GetInt("bestScore");
         FinishedGame();
     }
 
     void FinishedGame()
     {
         print(bestScore);
         if (score > bestScore)
         {
            bestScore = score;
             PlayerPrefs.SetInt("bestScore", bestScore);
             print("New High Score; " +
                 PlayerPrefs.GetInt("bestScore"));
         }
     }
 }
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

Answer by I_Am_Err00r · Jul 23, 2019 at 09:24 PM

It sounds like you are naming bestScore the same in both games.

 PlayerPrefs.SetInt("aGameBestScore", bestScore)
 PlayerPrefsSetInt("bGameBestScore", bestScore)

That should assign bestScore in each game to the specific archived best score.

Comment
Add comment · Show 2 · 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 robbos729 · Jul 23, 2019 at 09:44 PM 0
Share

Oh no in game one it's get int high score for 2 it's bestScore

avatar image I_Am_Err00r robbos729 · Jul 23, 2019 at 11:51 PM 0
Share

Are you sure you are not actually na$$anonymous$$g the string reference the same? You cant have it so that in game 1 you set the high score like this:

 PlayerPrefs.SetInt("bestScore", highScore);

and then in game 2 set it like this:

 PlayerPrefs.SetInt("bestScore", bestScore);

and expect them to be different; with that you are overwriting your original "bestScore" (set by game 1 as highScore) with the game 2 bestScore.

You would need to do something like I said earlier, and have two different string references to the PlayerPref variable, and then you can have just one int for best score because when you load the game, it will do this if game one:

 bestScore = PlayerPrefs.GetInt("aGameBestScore");

and it will set the variable bestScore to the PlayerPref reference, and of course vice versa for the game 2 PlayerPref.

 bestScore = PlayerPrefs.GetInt("bGameBestScore");


I hope that makes sense, but with PlayerPref you are creating a reference to an int with the string, and then calling that back at the load of a scene based on the same reference.

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

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

Related Questions

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

PlayerPrefs isn't saving between Scenes 1 Answer

How can I save highscores and display them for later? 1 Answer

Recognising high score when updated with a graphic 0 Answers

it is Playerprefs can use in saving highscore and both PC having this can same see data in Highscores? 0 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