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 blackshtormx · May 30, 2015 at 05:26 PM · speedscorecountersame

question about score counter

hi guys i have script that shows score. here it is:

 function show(){
 
 HowMuchToWait = 0.1;
 addScore();
 
 }
  
 function addScore(){
 for(effectScore=0; effectScore<=mascore; effectScore+=1){
 scoreText.text=effectScore.ToString();
 yield WaitForSeconds(HowMuchToWait);
 }
 }
 

it works properly but there is 1 mistake as i think. if ur score will be 1000000000 u have to wait a lot of time, so i need thing like that: if ur score is 50 u will wait for example 2 secs, if u have 1000000 same u have to wait 2 secs, any ideas? or is it dangerous that even if i make it work correctly comp will crash? XD thanks for any help

Comment
Add comment · Show 2
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 Crystalline · May 30, 2015 at 06:39 PM 0
Share

I dont get what for loop is doing there..

avatar image JSierraAKAMC · May 30, 2015 at 07:08 PM 0
Share

$$anonymous$$y understanding of the code is this: When the function show() is called, the variable How$$anonymous$$uchToWait is set to a value and addScore() is called. In the for loop in addScore(), you're starting from 0 and adding 1 to effectScore every time until it is less than mascore, which I assume is the score that you eventually want effectScore to be equal to. But every time effectScore is incremented, you must wait How$$anonymous$$uchToWait. This is where the problem is, I think, because you are waiting a length of time every time the score is incremented, ins$$anonymous$$d of having a fixed time to go from 0 to mascore.

1 Reply

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

Answer by JSierraAKAMC · May 30, 2015 at 07:24 PM

I created a script that does what I think you were trying to do here. #pragma strict

 var mascore : int = 0;
 var effectScore : int = 0;
 var HowMuchToWait : float = 0.1;
 //How long the entire process takes
 var waitTime : float = 2;
 private var currentTime : float = 0;
 private var hasCompleted : boolean = true;
 var scoreText : TextMesh;
 
 function Update () {
     if(Input.GetButtonDown("Fire1")){
         mascore += 100;
         show();
     }
 
     //New way:
     //If it isn't complete,
     if(!hasCompleted){
         currentTime += Time.deltaTime;
         //Start incrementing the currentTime by the time since the last frame
         scoreText.text = Mathf.FloorToInt(Mathf.Lerp(0, mascore, currentTime/waitTime)).ToString();
         //Set the text 
         if(currentTime >= waitTime){
             currentTime = 0;
             hasCompleted = true;
         }
     }
 }
 
 function show(){
     HowMuchToWait = 0.1;
     //Old way:
     //addScore();
     //New way:
     hasCompleted = false;
 }
 //Old way:
 function addScore(){
     for(effectScore = 0; effectScore <= mascore; effectScore++){
         scoreText.text = effectScore.ToString();
         yield WaitForSeconds(HowMuchToWait);
     }
 }
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 blackshtormx · May 31, 2015 at 03:23 AM 0
Share

thank you!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Uniting 2 integers from two different sources 1 Answer

Make a custom score counter in unity with c# 1 Answer

Connecting 2 scripts(javascpt)? 2 Answers

how to keep track of bricks broken 1 Answer

Do something every each multiple of 1000.. 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