Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by KraykonDev · Feb 17, 2016 at 01:49 PM · 2denemytimecaracceleration

make enemy cars spawn faster over time!

hi i got this script that spawns 5 cars every 0.8 seconds but i want them to spawn faster and faster after time so maybe after every 20 seconds the the 5 cars spawn every 0.7 seconds and i want it to stop to accelerate when it is 0.4 please help me i am having big trouble with this, here is my script:

 public GameObject[] Cars;
 int carNo;
 public float delayTimer = 1f;
 float Timer;

 void Start () {


     Timer = delayTimer;
 
 }

 void Update () {

     Timer -= Time.deltaTime;
     if (Timer <= 0)
     {

         Vector3 carPos = new Vector3(Random.Range(-2.2f, 2.2f), transform.position.y, transform.position.z);
         carNo = Random.Range(0,5);
         Instantiate(Cars[carNo], carPos, transform.rotation);
         Timer = delayTimer;     
         
               
     }

}

Comment
Add comment · Show 4
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 KraykonDev · Feb 17, 2016 at 01:51 PM 0
Share

the script works great and it spawns the objects but i want it to spawn faster and faster so the game gets more difficult .

avatar image Nerevar KraykonDev · Feb 17, 2016 at 02:07 PM 1
Share

You need to think a bit about the game design first. There are several ways: you can look at the time remaining, the time spent on the level, or a fixed time step to modify the spawn rate.

so every 20 seconds you want reduce the timespan between spanw by 0.1 is that correct?(with max at 0.4)

You need to implement another time as the one already in you script but initializing at 20f I suggest you take more explicit names for the variables.

 //Global
 public float delayTimer2 = 20f;
  float Timer2;


  //In Update
  Timer2 -= Time.deltaTime;
  if (Timer2 <= 0)
  {
          if( delayTimer>0.5f){
              delayTimer -=0.1f
          }
       Timer2 = delayTimer2 ;
 }

this above code will go in update as well

avatar image KraykonDev Nerevar · Feb 17, 2016 at 03:47 PM 0
Share

Let me try that in game and thanks for answering early

avatar image KraykonDev KraykonDev · Feb 17, 2016 at 05:34 PM 0
Share

It works but it goes directly to 0.5 i want to go from 0.8 to 0.7 to 0.6 and then 0.5 and i want this to happened every 20 seconds here is the script again:

 //Acceleration...
 public float delayTimer2 = 20f;
 float Timer2;
     


 public GameObject[] Cars;
 int carNo;
 public float delayTimer = 1f;
 float Timer;

 void Start () {

     


     Timer = delayTimer;
 
 }

 void Update () {

     Timer2 -= Time.deltaTime;
     Timer2 = delayTimer2;
     if(Timer2 <= 0)
     {
         if(delayTimer > 0.5f)
         {
             delayTimer -= 0.1f;
         }
     }


     Timer -= Time.deltaTime;
     if (Timer <= 0)
     {

         Vector3 carPos = new Vector3(Random.Range(-2.2f, 2.2f), transform.position.y, transform.position.z);
         carNo = Random.Range(0,5);
         Instantiate(Cars[carNo], carPos, transform.rotation);
         Timer = delayTimer;     
         
               
     }

}

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by anggarp · Feb 18, 2016 at 01:53 PM

u problem same with me because we use the same code exactly. are u solve the problem yet? please tell me

Comment
Add comment · 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
0

Answer by patrickharvey · Aug 29, 2017 at 12:47 PM

can someone can solve this problem? it will help alot for who will helped .

Comment
Add comment · 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

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

67 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 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 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 avatar image

Related Questions

Time Based Scoring - 2D Endless Runner ,Time based scoring system 0 Answers

2D Enemy Ai 0 Answers

How can I do an Enemy while He's walking his HEAD always see the Target? 1 Answer

How to add a timer to say wait for 5 s from now if bools are true? 1 Answer

WheelCollider motorTorque acceleration with ps4 triggers 0 Answers


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