- Home /
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
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
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?
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.
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.
Yes a simple function call. You need to setup both "oncomplete" and "oncompletetarget" when you make the iTween call for the callback to work.
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?
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.
$$anonymous$$athf.Clamp method actually seems fine to me. Both of those are great solutions. Thank you very much!
Your answer
![](https://koobas.hobune.stream/wayback/20220613094028im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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