Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
This question was closed Oct 13, 2020 at 08:52 PM by Hero247 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Hero247 · Oct 13, 2020 at 05:58 AM · timetime.deltatimecounterincreasetime.timescale

How to Make Timer (Score) Count Up Faster?

I'm trying to increase the score counting speed slowly over time. Right now, all it does is add 1 second every actual second. I'd like it to slowly increase the speed in which it counts. So eventually, it'd be running at something like 2.3 score per actual second. So on and so forth.

public class Score : MonoBehaviour

{ private float score = 0.0f;

 public Text scoreText;

 void Update()
 {
     score += Time.deltaTime;
     scoreText.text = ((int)score).ToString ();
 }

}

EDIT: Here is the code I ended up using:

private float score = 0.0f;

public Text scoreText;

public float speedFactor = 1.0f;

void Update() { speedFactor += Time.deltaTime / 10;

  score += Time.deltaTime * speedFactor;

  scoreText.text = ((int)score).ToString ();

}

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

  • Sort: 
avatar image
0

Answer by streeetwalker · Oct 13, 2020 at 06:14 AM

You need 2 more variables. You need a speed and a running score. You are going to multiply running score by a speed factor, say speedFactor, after you add Time.deltaTime to it. then add the result to score. Running score will need to be reset to zero after every second. Start with the speedFactor = 1;

For example:

 runningScore += time.DeltaTime;
 if( runningScore < 1.0f ){
      runningScore *= speeFactor;
 }else{
      runningScore = 0;
 }
 Score+= runningScore;



You need to do this because you don't want the score to grow exponentially each pass.

You have decide how often to increase speedFactor and by how much - and how long it is before "eventually" happens.

Eventually speedfactor = 2.3, because as you state you want to add 2.3 every second, eventually.

So at this point you need to detail exactly how you want that to happen between your game start and eventually.

Comment
Add comment · Show 6 · 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 Hero247 · Oct 13, 2020 at 06:26 AM 0
Share

I think I get what you're saying. Just so we're clear here, what I'm trying to do is increase the score by 1 per second, but that 1 per second will change to 1.1 the next second, and 1.2 on the second after that. So for example, after 4 actual seconds, the score would be 4.6 because of 1.0 + 1.1 + 1.2 + 1.3

I'm sorry if I'm not making sense...

avatar image streeetwalker Hero247 · Oct 13, 2020 at 06:28 AM 0
Share

actually, I just edited the answer - it's a little more subtle than that. I don't think you want your score to grow exponentially, which is what will happen. So I think the sample code I posted fixes that.

avatar image streeetwalker Hero247 · Oct 13, 2020 at 06:31 AM 1
Share

OK, and if you want to increase every second on the second, then inside the else where the code sets runningScore back to 0, increase speedFactor by what ever increment you want. You will also want to put an if there (or use a clamp statement) to limit speedFactor to 2.3

avatar image Hero247 streeetwalker · Oct 13, 2020 at 06:34 AM 0
Share

Okay okay, I think I gotcha. I'll try this out tomorrow after work. I'll let you know how it goes. Thanks!

avatar image streeetwalker Hero247 · Oct 13, 2020 at 06:43 AM 1
Share

On further thought, I'm not sure my answer is correct yet.

Think about it. Every second you want to add an increasing value to the score, starting out at 1 per second and ending at 2.3 per second.

You do need a speedFactor and a running score, but the question is how to achieve the above.

The question is, do you need to add this in every frame, or only when each second is up?

$$anonymous$$ultiplying Time.deltaTime by a speedFactor will increase the rate of increase every frame, and you could do that directly:

speed += Time.deltaTime * speedFactor without any of the extra code.

Then you just need to increase speedFactor and limit it.

If you want to increase it on the second, and not continuously, then you do need another variable to tell you when a second has expired.

avatar image Hero247 streeetwalker · Oct 13, 2020 at 08:50 PM 0
Share

thanks for all your help, you got me sent in the right direction. I ended up with this code:

 private float score = 0.0f;

 public Text scoreText;

 public float speedFactor = 1.0f;

 void Update()
 {
     speedFactor += Time.deltaTime / 10;

     score += Time.deltaTime * speedFactor;

     scoreText.text = ((int)score).ToString ();
 }

Follow this Question

Answers Answers and Comments

213 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 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

A Good Substitute For yield WaitForSeconds() 0 Answers

Returning abnormal values with Time.deltaTime and Time.unscaledDeltaTime. 0 Answers

How to pause my game when using Time.DeltaTime? 0 Answers

movement speed still changes with FPS; Despite using Time.deltaTime (And GetAxisRaw)! 0 Answers

Confused about waitforsconds and need help with making slowmotion only last for a certain number of seconds and then cool down 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