Trouble with score management.
So I've got 2 projectiles heading towards a trigger object.
When the 2 projectiles hit (at the same time), I'd like to add 1 point, but it currently adds 2 points since there are 2 projectiles which collide at the same time. Below is my current code; .
.
I'm wondering if anyone has any ideas, I've tried dividing by 2 but then it doesnt count...
Grateful for any help ;D
Answer by lvskiprof · Nov 22, 2021 at 05:37 PM
Well if two projectiles hit at the same time the damage should be doubled, so not sure why you don't want to count them both. However, the reason dividing by 2 is not working is because you are using an integer for score, I believe. You don't show the code here that is doing the divide by 2, so I can't be sure, but if the result of the divide by 2 ends up being a fraction (like 1/2) it will drop the fraction when converting the result to an integer. Since you are probably doing that for both projectiles the result is that neither count as a hit.
I am curious how you are detecting that both hit at the same time. It might help if you shared that code.
Thanks for the reply!
This is not about damage, it's about adding score.
Series of 2 objects are traveling towards, and will pass through, a trigger. When the 2 objects collide with the trigger it will add a point for each object that has passed through. Because they come in series of 2, this will add 2 points. But for my specific application, I only wish to add 1 point for each set of 2 objects that pass through!
I believe what you said regarding the fraction rounding off to 0 is precisely my issue here.
The code is all there, not at my computer right now but could post the code I've got for the projectile later ;p.
Thanks again!
Your answer
Follow this Question
Related Questions
Move UI panel on and off screen, scripted without animation 0 Answers
Using downloaded image as UI Image's source image? 1 Answer
ObjectReference Not set to an instance of an object 1 Answer
Unity 5.3 UI Button wont set Select state via script after the parent has been set inactive 0 Answers
Is there a way I can make one script for all my buttons in my game? 1 Answer