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 youngapprentice · Mar 08, 2013 at 01:39 AM · javascriptitweenincrement

Point Incrementation

Hi, all! In my game, I have a very simple iTween call that is called when an enemy is killed. This increments the score by, say, 20 points. It gets animated nicely and changes the value. I like it a lot, but when multiple enemies are destroyed at the same time (explosion), only the point value for the first enemy gets incremented.

Say 3 enemies are killed almost simultaneously that all have a payoff of 20 points. Only 20 points will be added as opposed to 60.

Is there a way I can work around this?

Any ideas are much appreciated.

Thanks!- YA

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 angrycarrots · Mar 08, 2013 at 01:42 AM 0
Share

use time.time so that when an enemy is killed during your "kill cooldown", it will reset the timer so that evey point will only equal 20. when the timer runs out, every kill would be awarded 20 points and then the timer would reset

avatar image youngapprentice · Mar 08, 2013 at 01:48 AM 0
Share

I'm sorry but could you embellish a little? Are you saying I should store a temporary variable of total points gathered in under, say, 3 seconds, and once the timer is set off before any kills are gained, I should the increment the value? But wouldn't that add an awkward point delay when killing single enemies?

1 Reply

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

Answer by robertbu · Mar 08, 2013 at 02:03 AM

One solution:

  • iTween has the "oncomplete" and "oncompletetarget" hash values that allow you to setup a callback when an iTween completes. You set a boolean (like bScoring) to true when you launch the iTween, and to false when you get the oncomplete callback.

  • You setup a variable that accrues new points.

  • In Update() if your bRunning is false and there are points to be scored you, 1) set bRunning to true, subtract 20 points, and launch the next iTween.

This way you will get iTweens running in sequence.

Comment
Add comment · Show 5 · 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 youngapprentice · Mar 08, 2013 at 02:16 AM 0
Share

Nice. So the oncomplete would just be a simple function call to set the boolean back to false. And this would repeat while the accrued number of points is above zero. Nice solution. thank you.

avatar image robertbu · Mar 08, 2013 at 02:22 AM 0
Share

Yes a simple function call. You need to setup both "oncomplete" and "oncompletetarget" when you make the iTween call for the callback to work.

avatar image youngapprentice · Mar 08, 2013 at 02:32 AM 0
Share

Seems pretty straightforward to me. If the bool is false, it is just added to the variable holding points, while a constant loop goes on as long as the point holder is greater than 0 it will increment in x amount of points. I see one problem here. Different enemies have different point payoffs. How am I supposed to know when I have the last piece of the pie left, and how much I should take a way when I do?

avatar image robertbu · Mar 08, 2013 at 03:41 AM 0
Share

I can think of a couple of ways. First, you can simply use $$anonymous$$athf.Clamp(). Something like:

 var pointsToTakeOff = $$anonymous$$athf.Clamp(pointsAvailable, 1, 20);
 pointsAvailable = pointsAvailable - pointsToTakeOff;

If you really want your counter to move in sync with the point values, then you can create an a list for your for your scores, and store each score independently. An ArrayList, a generic List, or a Queue would work, especially given the small number of items it will hold. Each time bScoring is false, you would pull another value from the queue.

avatar image youngapprentice · Mar 08, 2013 at 12:12 PM 0
Share

$$anonymous$$athf.Clamp method actually seems fine to me. Both of those are great solutions. Thank you very much!

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

11 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

Related Questions

Another collision detection issue 1 Answer

Saving an Object of a Class 1 Answer

Gun State Machine 1 Answer

Grid Creation from Center 2 Answers

Physical Representations of a Class (Most likely simpler than it sounds) 1 Answer


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