Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsamgaudet
8,451 Pointssome how ShildedInvader has infinite health
whenever I run the game it is able to kill all the regular invaders but then it tries to hit the shielded one and hits it like 8 times and then the player loses
workspace snapshot: https://w.trhou.se/55mzwd91a9
1 Answer
Steven Parker
231,264 PointsIn "ShieldedInvader.cs", on line 10, there is this test for potential damage:
if(_random.NextDouble() < 0) {
So this would apply damage when "NextDouble" returns a negative number. But according to the documentation page, that method returns "A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0."
So that would mean no shot would ever hit.
You probably want a number other than 0 to indicate a percentage chance of being hit, like 0.6 for 60%.