The game is supposed to increase the level by 1 every 10 spawns of an object, using totalShots % 10 == 0. So, when totalShots is equal to 10, 20, 30, etc. the level should increase by 1, however, the level keeps on increasing in the time between the 10th and 11th spawn (example: http://gfycat.com/ArtisticAdorableGreatwhiteshark).
This is the code:
var totalShots : int = 0;
var level : int = 0;
function Start () {
}
function Update () {
transform.Translate(Vector3(0, direction * speed * Time.deltaTime, 0));
if (Time.time > lastSpawn + nextSpawn){
Instantiate(shot, new Vector3(transform.position.x - 1, transform.position.y, transform.position.z), Quaternion.identity);
totalShots++;
lastSpawn = Time.time;
nextSpawn = Random.Range(2, 3);
}
}
function ShotCounter() {
if(totalShots % 10 == 0){
level++;
}
return(level);
}
Should this code be working or is there something that I am doing wrong? How can I make it so that the level only increases by 1?