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 Traczy · Aug 17, 2015 at 07:22 PM · highscoressetzero

Check when closest to 0

The point of my game is to be as close to 0 as possible. How can I set highscore based on how close you are to 0. Let's say the last highscore is 0.12, then I get 0.09, then that should be the new high score. Then let's say I get -0.02, than that's the new highscore. I know how to use get and set int/float, so that's not what i'm asking. I'd really appreciate answers!

Comment
Add comment · Show 3
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 jimmycrazyskills · Aug 17, 2015 at 07:37 PM 0
Share

Hey! I'm not sure if this would work but you could do a check each time the score is created and if it is a highscore overwrite a variable. For example:

 var score;
 var highscore;
 
 if(score < 0){
     if(highscore < 0){
           if((score * -1) < (highscore * -1)){
                 highscore = score;
           }
     }
     else{
           if((score * -1) < highscore){
                 highscore = score;
           }
     }
 }
 else{
     if(highscore < 0){
           if(score < (highscore * -1)){
                 highscore = score;
           }
     }
     else{
           if(score < highscore){
                 highscore = score;
           }
     }
 }

I haven't tested this but I think it might work, sorry if this isn't what your looking for :) Hopefully what this does is check if the score is negative and multiplies by -1 if it is(this will give us a positive value to compare to). Then the same is done for the current highscore incase that is negative as well e.g -0.02 . Then the closest to 0 value should be saved into highscore. P.S This is not refactored, you can probably write the same code in a couple of lines but i'm a noob :)

avatar image jimmycrazyskills · Aug 17, 2015 at 07:46 PM 0
Share

See answer below for the shorter version LOL:)

avatar image Traczy · Aug 17, 2015 at 08:14 PM 0
Share

Yea, made it work with that method. Thanks anyways :)

2 Replies

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

Answer by $$anonymous$$ · Aug 17, 2015 at 07:32 PM

There is not enough information here to really be able to help you a whole lot. Do you want something like:

 if (Mathf.Abs(newScore) < Mathf.Abs(highscore)) highscore = newScore;

This checks the absolute value of the new score and compares it's total distance from zero to the current highscore's.

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 Traczy · Aug 17, 2015 at 08:00 PM 0
Share

Great! Just what I needed, made it work perfectly.

avatar image
0

Answer by Maui-M · Aug 17, 2015 at 07:37 PM

You can use absolute value to normalize the values then take the lowest one.

 if(Mathf.Abs(score) < Mathf.Abs(highscore))
    highscore = score;

http://docs.unity3d.com/ScriptReference/Mathf.Abs.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

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

27 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

Related Questions

Server High Scores - crossdomain.xml 1 Answer

it is Playerprefs can use in saving highscore and both PC having this can same see data in Highscores? 0 Answers

Saving final score and displaying on main menu 1 Answer

Is there a way to encrypt/lock a File.CreateText file? (its my highscore) 1 Answer

how to add highscore tab on this code 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