How do I make an if statement run only once. I am making a game in javascript and once the users score is 5 I want to add a new enemy into the array. The problem I am having is once the if statement is true it keeps adding new enemies over and over until the whole screen is covered with enemies. I want it to add only 1 new enemy when score is 5 then another when score is 10 and so on. I cannot think of a way to accomplish this. Thank You.
Sketch.js
var score = 0;
//3 three enemies once game starts
function StartingEnemies() {
for (var i = 0; i < 2; i++) {
enemies[i] = new BasicEnemy();
}
}
//add new enemies into the array
function spawnNewEnemies() {
enemies.push(new BasicEnemy());
}
if (score == 5) {
spawnNewEnemies();
}