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
1
Question by ChompIV · Feb 06, 2017 at 08:30 AM · playerprefsmenuscore

How would I make a high score thing? (it would be on a seperate scene)

So I have a points stystem, but I want to add a high score in the main menu. Right now its in a canvas and text and here's the scripts, i really need help thanks!

One script that shows how much points go in fo each bullet:

 function DeductPoints (DamageAmount : int) {
     GlobalScore.CurrentScore +=10;
 }



Script for score popping up in game:

 static var CurrentScore : int;
 var InternalScore : int;
 
 var ScoreText : GameObject;
 
 function Update () {
     InternalScore = CurrentScore;
     ScoreText.GetComponent.<Text>().text = "" + InternalScore;
 }


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
1

Answer by game4444 · Feb 06, 2017 at 11:47 AM

Hi, Are you saving your score anywhere? What i would i do in your case. In my gameOver condition i will save score in PlayerPrefs. e.g PlayerPrefs.setInt("highscore",LastscoreValue); And in MainMenu script previousScore = PlayerPrefs.getInt("highScore"); newHighScore = Mathf.Max(previousScore, GlobalScore.CurrentScore); //It will return me max value. then again PlayerPrefs.setInt("HighScore",newHighScore); //It will update HighScore value with newHighScore. You can read about playerPrefs here: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

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

Answer by RonanSmithDev · Feb 06, 2017 at 10:33 AM

I am not sure about the specific code but you should start looking into either Player Prefs (https://docs.unity3d.com/ScriptReference/PlayerPrefs.html) or maybe some sort of Serialization (https://docs.unity3d.com/Manual/script-Serialization.html).

Both of these methods store data in a file that you can read and transfer data from any scene and can be made to store the data even if the game/application is closed and opened (Basically perfect for score/game-progress saving)

Player Preferences is the easiest by far to get to grips with but it has downsides, it is stored on the device in a text type file that can be easily manipulated by users to cheat high scores but if your game is standalone with no leader board or online feature this won't matter. PlayerPrefs uses simple scripts to set, get and look-up variables in an external script. An example here: (https://forum.unity3d.com/threads/example-of-using-player-prefs-to-save-and-get-a-variable.42398/)

Serialization is harder to use because it is not built into Unity as well as PlayerPrefs but can potentially be more flexible.

It's just a place to start, hope this helps!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Guide in ArrayPrefs or PlayerPrefx? 1 Answer

PlayerPrefs Highscore problem 1 Answer

calculate playerprefs and display 1 Answer

DontDestroyOnLoad reset the gameobject 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