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 Rick74 · Dec 03, 2013 at 06:01 PM · javascriptscore

Revised; a fancy method of adding value to a score?

I put revised in the title because I've asked this same question before, and the answer I got, I thought would work. But after diving in, I'm left frustrated. (well technically the answer was sound, it just didn't give me the results I was after)

The look I'm going for is to have a value (score) get values added to it and have the score count up to that new value, hitting every number.

I've been playing around with Mathf.Lerp, as was suggested to me in the previous question, but they seem to only display certain numbers on its way to the new value.

So if I'm adding 25 to 100, and I'm using a lerp...I'll maybe see the numbers 110,113,117,122 - 125. Which isn't the look I'm going for. I want to see every number as the score races to its new value.

Anyone have any ideas, or have encountered this situation?

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 Scribe · Dec 03, 2013 at 06:22 PM 2
Share

should the final number be reached in a specified amount of time or is the time taking to reach the answer flexible. If the time is fixed it might not be physically possible to show all numbers due to the number only being visibly changed on a frame change, which is restricted by the FPS?

1 Reply

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

Answer by Jessy · Dec 03, 2013 at 06:21 PM

You haven't explained why you don't "see" the numbers. If you want to increase by 1 every frame, then do this:

 void Update(){
  if (displayedScore != score) displayedScore++;
 }
Comment
Add comment · Show 4 · 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 Rick74 · Dec 03, 2013 at 06:26 PM 0
Share

$$anonymous$$aybe I'm just trying to add to much value and have it lerp it too short of a time. I'm not asking this question the right way.

This is the code I have currently.

 #pragma strict
 
 var Start_Number:     int = 0;
 var End_Number:        int = 25;
 var current_Number:    int = 0;
 var Lerp_Slider        = 0.0;
 
 function Update ()
 {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Q))
     {
         $$anonymous$$athlerp ();
     }
     if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Q))
     {
         current_Number = 0;
     }
 }
 
 function $$anonymous$$athlerp ()
 {
     var t: float = 0;
     
     while (t < 1)
     {
         current_Number = $$anonymous$$athf.Lerp(current_Number, End_Number, Lerp_Slider + t);
         t += .1;
         yield WaitForSeconds (.1);
         print (t);
     }
 }

$$anonymous$$aybe it's a FPS issue on my computer, but when I look over at the value as it goes up. It doesn't do it smoothly, it just jumps to values on it's way to the new score.

avatar image Scribe · Dec 03, 2013 at 06:43 PM 1
Share

Have you tried Jessy's suggestion, I guess this would be the implementation:

 var score : int = 100;
 var displayedScore : int;
 var scoreDiff : int;
 
 function Start () {
     displayedScore = score;
 }
 
 function Update () {
     if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Q)){
         score += 25;
     }
     if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.W)){
         score -= 25;
     }
     
     if(displayedScore != score){
         scoreDiff = score-displayedScore;
         displayedScore += scoreDiff/$$anonymous$$athf.Abs(scoreDiff);
     }
 }
 
 function OnGUI(){
     GUI.Label(Rect(0, 30, 100, 20), "Score: " + displayedScore);
 }
avatar image Rick74 · Dec 03, 2013 at 06:47 PM 0
Share

I'll give it a shot!

avatar image Rick74 · Dec 03, 2013 at 06:49 PM 0
Share

Yes! That looks 100 times better, and more to what I was after! Now I need to go look up $$anonymous$$athf.Abs

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

19 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

Related Questions

Keeping track of items 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Can I reference a gameObject in a script attached to a different gameObject? 2 Answers

Trying to make simple trigger score counter, having troubles. 0 Answers

Pause When Score Reached? 2 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