- Home /
 
How to add a peaking system?
Hi Jeremy here! The code below spawns 2 bubbles and when it reaches 10 bubbles spawned it adds 1 and then when it reaches 20 it adds another and so on! It works great but I want to add a peaking system so that once the amount of bubbles on screen reaches a number between 100 and like 120 it will reset how many are spawning to a low number that way it never gets to a point where theres more than 120 bubbles on screen? Any suggestions would be greatly appreciated! Thanks
 #pragma strict
 
 var projectile : Rigidbody2D;
 var spawnRadius : float;
 var projectileSpawnRate : float;
 private var projectileSpawnAmount = 2;
 
 var totalBalloons = 0;
 var Initial = 10;
 
 InvokeRepeating("Spawn", 2, projectileSpawnRate);
 
 function Spawn () {
 
     for (var i : int = 0; i < projectileSpawnAmount; i++) {
            var instance : Rigidbody2D = Instantiate(projectile);
         instance.velocity = Random.insideUnitSphere * spawnRadius;
         totalBalloons += 1;
         
 //        Debug.Log("Initial: " + Initial);
 //        Debug.Log("Balloon Spawned: " + totalBalloons);
         
         if (totalBalloons >= Initial) {
             
             projectileSpawnAmount = projectileSpawnAmount + 1;
             Initial = Initial + 10;
         }
     }
 }
 
              Answer by Slobdell · Apr 01, 2014 at 07:22 PM
Just change this
 projectileSpawnAmount = projectileSpawnAmount + 1;
 
               To
 projectileSpawnAmount = totalBalloons > 100 ? 5 : projectileSpawnAmount++;
 
              Could you explain what this would do exactly Slobdell?
Google ternary operator, it's an if/then with more finesse
Thanks Slobdell I had to delete the line below also for it to work but in my question I wanted it so that after it sets the spawn amount to 5 continue the loop of adding one every 10.
      `Initial = Initial + 10`;
 
                 Your answer