• 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 G_Sacristan · May 31, 2011 at 05:30 PM · score

WaitForSeconds little trouble

  function AddScore()
 {
         scoringIsActive=true;
         enterTime=Time.time;
         while(tempScore>0)
         {
             scoreNumberTxt.text=score+"";
             tempTxt.text="+"+tempScore;
             
             if(Time.time-enterTime<1.0) yield WaitForSeconds(0.5);
             else yield WaitForSeconds(0.001);
             tempScore--;
             score++;
         }
         scoringIsActive=true;

}

The idea of it that i want to slowly subdivide tempScore and add score for a second then do it very fast... there was another algorithm that used Time.time, but it didnt work, too!

Have anyone an idea?

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 Owen-Reynolds · May 31, 2011 at 07:15 PM 0
Share

Looks like the right idea. Right now it adds a point every 1/2 sec for 1 second, before blasting in 1/frame. So, you only slow-count 1 number. You might increase the 1.0 seconds. Or you could decrease the wait to maybe 0.2 (so you get +5 over the first second, then blast them in.)

avatar image Mike 3 · May 31, 2011 at 07:17 PM 0
Share

done like this coroutines are VERY inaccurate - 0.001 second wait will wait at least one frame, which could be 0.04 seconds or anything

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by save · May 31, 2011 at 07:29 PM

Wouldn't it be both easier and faster to use:

 var newScore = Mathf.Lerp(score, score+tempScore, Time.time);
 score = newScore;
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 aldonaletto · May 31, 2011 at 08:58 PM

I've not tested this script yet, but it should do what you want. In order to add some value to the score, just store the value to add in tempScore: the score will rise in a slow pace and after reach the time defined in slowTime it will go up 1 per frame

private var lastScore:int =-1; private var nextTime:float; private var slowTime:float;

function Update(){

 if (tempScore>0){
   if (tempScore>lastScore){
     lastScore = tempScore;
     nextTime = Time.time;
     slowTime = nextTime+2; // slow for 2 seconds
   }
   if (Time.time>=nextTime){
     scoreNumberTxt.text=score+"";
     tempTxt.text="+"+tempScore;
     if (Time.time<slowTime)
       nextTime += 0.5; // slow pace
     else
       nextTime += 0.001; // fast pace
     tempScore--;
     lastScore = tempScore;
     score++;
   }
 }

 





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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Keeping a score from one scene to another? 2 Answers

Play Sound on Score 2 Answers

score not add in the gui text 2 Answers

Score multiplier/ chaining system 1 Answer

how to save score in a system as a file in unity3d 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