Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jammer3000 · Mar 31, 2014 at 06:11 PM · javascriptspawn

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;
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Slobdell · Apr 01, 2014 at 07:22 PM

Just change this

 projectileSpawnAmount = projectileSpawnAmount + 1;

To

 projectileSpawnAmount = totalBalloons > 100 ? 5 : projectileSpawnAmount++;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jammer3000 · Apr 02, 2014 at 12:25 AM 0
Share

Could you explain what this would do exactly Slobdell?

avatar image getyour411 · Apr 02, 2014 at 12:26 AM 0
Share

Google ternary operator, it's an if/then with more finesse

avatar image Jammer3000 · Apr 02, 2014 at 04:09 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GetComponentInChildren(Renderer).active wont work? 2 Answers

Attach object as child using code 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

How to toggle a key for a car to go forward or backward? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges