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
2
Question by .hooligan · Jan 22, 2011 at 11:01 AM · scoring

Score count up to target score - works tooo fast

I was wondering how I would slow down the following.

I'm trying to make one of the old game scores that when you get some points it counts up to the total score or a second or so depending on the sizer of the number. I have this working but because the processing of unity and fps is so fast that it appears at the number instantly. But when I print out the score it counts up correctly.

What I did was just get the difference and then half it and increment it by that until it reaches the target score.

So if score was 0 and the player just got 50 pts the score would quickly count up to 50.

0, 25, 37, 43, 46, 48, 49, 50

The only problem I'm having is that it appears instantly. Are there any methods of slowing this sort of thing down? Or is there a better way to do this?

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 azzogat · Jan 22, 2011 at 01:11 PM 0
Share

please post the code you have so far.

5 Replies

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

Answer by Thom Denick · Jan 22, 2011 at 04:58 PM

Here's the code I used in my project... It's in C#, but I think it's identical to JS here:

int score = 500000; float textBaseScoreIncreaseAnimationSpeed = 5.0f;

//Figure out what % of our total time our current frame occupies. //We do this by dividing the Time.deltaTime(time since last frame had been drawn) //By the amount of time we want our scroll-up to last. In this case, if our //deltaTime is 0.1, than we get a scoreMultiplier of 0.02. float scoreMultiplier = Time.deltaTime / textBaseScoreIncreaseAnimationSpeed;

//Simply multiply our total score against the new multiplier.

float scoreAdd = score * scoreMultiplier;

//Since we dealt with time, we had to use floats to calculate.
//This simply converts our number to an integer.

int scoreAddRound = Mathf.Ceil(scoreAdd);

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 .hooligan · Jan 23, 2011 at 12:39 AM 0
Share

Thanks Smorpheus, works a treat. Even more simple then the way I was doing it.

avatar image Thom Denick · Jan 23, 2011 at 01:40 AM 0
Share

No problem. One of the advantages of explaining your own code is when you need to share. :)

avatar image .hooligan · Feb 18, 2011 at 04:07 AM 0
Share

Hey Smorpheus, I've been using your script and all working fine. I noticed I has sort of an irregular count up.

eg,

goes from 1, 5, 7, 9, 11, 15, 16, 18, 20, 22.

Is that because of the Time.delta that I get weird jumps if not it counts by 2? Is there a way to change the formula so it has a division by 2

eg 1 - 50

25 37 43 46 48 49 50 ? These are all converted to floor ints

avatar image Thom Denick · Feb 18, 2011 at 04:17 PM 1
Share

Yeah this is really designed for counting up large numbers like multi-thousand point scores. Your jumps are happening because of Time.Delta I believe. Anyway, to get it to just count up in regular intervals just get rid of the Time.deltaTime and replace that with a flat float like 0.2f

avatar image
2

Answer by code-sumit · Nov 16, 2014 at 12:52 PM

Try this :-

     using UnityEngine;
     using UnityEngine.UI;
     using System.Collections;
     
     public class FinalScores : MonoBehaviour 
     {
        public Text ScoreText;
        public float CountInterval = 0.05f, timer=0;
        int Score = 500, i=0;
     
        void Update()
        {
           timer+=Time.deltaTime;
     
           if(i<Score && timer>=CountInterval)
            {
                i++;
                ScoreText.text=i.ToString ();
                timer=0;
            }
        }
     }


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
1

Answer by zmar0519 · Jan 22, 2011 at 02:22 PM

you could, if you were trying to add score incrementally, you could use the x *Time.deltaTime. also, you could have each frame add to a dumb var (traditionally i) and when it reaches a point, you add score and set i to 0.

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 Jessy · Jan 22, 2011 at 01:54 PM

http://unity3d.com/support/documentation/ScriptReference/index.Keeping_Track_of_Time.html

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 Manoj Balaji Mohan · Feb 17, 2016 at 07:32 AM 0
Share

this URL is not working. can you please give some other reference?

avatar image
0

Answer by user-11096 (google) · Apr 21, 2011 at 01:45 AM

Well i hope this works for you but you got to the game must check to see how fast you want things to go. In your function add this.

var seconds : int = Time.time;
var oddeven = (secodns %2)
if(oddeven)
{
    Shoot(seconds)
}

also add a new function like shown, this function is used to find the seconds and saved time.

    function Shoot(seconds)
{
    if(seconds!=savedTime)
    {
        savedTime=seconds;
    }
}

add a variable called

var savedTime = 0;

Well hope this script works for your, feel free to change the Shoot function to something what your really need to be like points time or what ever. But this is a example on saviing time in unity3d.

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 .hooligan · Apr 27, 2011 at 01:56 AM 0
Share

Thanks heaps for the reply. Really helps

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

2 People are following this question.

avatar image avatar image

Related Questions

Scoring system 2 Answers

Trying to sync score on multiplayer LAN game 0 Answers

How do I keep the highest scoring value for a game session? 2 Answers

scoring sing guiText 2 Answers

BCE0019: 'GetComponent' is not a member of 'Object'. 3 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