ifステートメントのカウントを追跡するためにvarカウントを取得できません。誰か助けてください
Laser.prototype.update = function () {
//.3
this.rot += .3
this.pos.add(this.dir.clone().mult(5));
this.alive = !(this.pos.x > cw || this.pos.x < 0 || this.pos.y > ch || this.pos.y < 0);
var counts = 0;
for (var i = 0; i < asteroids.length; i++) {
var astPos = asteroids[i].pos.clone();
astPos.sub(this.pos); //3 impact area
if (asteroids[i].onscreen && astPos.len() < asteroids[i].sizes[asteroids[i].level] + 10) {
asteroids[i].hit(this.dir);
if (counts < 5) {
this.alive = false;
counts++;
//alert("the count is" + counts);
}
if (counts > 5) {
this.alive = true;
counts++;
alert("the count is" + counts);
}
return counts;
}
}
}