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 heyhujiao · Dec 20, 2015 at 03:15 PM · c#timespawngame object

How to set Game Object to spawn after a certain timing After Level Loads?

Hello guys! I have a script that spawns my kill objects. I want my kill objects to spawn after 5 secs, 20secs, 60secs, 90secs so that I will have a total of 5 kill objects in the game after 90 secs. Any idea how to do that?

The following is my kill object spawning script :

 using UnityEngine;
 using System.Collections;
 
 public class KillObjectGenerator : MonoBehaviour
 {
 
     public float randomTimeDelay;
     private float randomTimeDelay2;
     private float randomTimeDelay3;
     private float randomTimeDelay4;
     private float randomTimeDelay5;
     public GameObject cloud;
     public GameObject lightning;
     private float randomX;
     private Vector2 newPositionL;
     private Vector2 newPositionC;
     private Vector2 newPositionL1;
     private Vector2 newPositionC1;
     private Vector2 newPositionL2;
     private Vector2 newPositionC2;
     private Vector2 newPositionL3;
     private Vector2 newPositionC3;
     private Vector2 newPositionL4;
     private Vector2 newPositionC4;
 
     void Start()
     {
         randomTimeDelay = Random.Range(3f, 6f);
         randomTimeDelay2 = Random.Range(3f, 6f);
         randomTimeDelay3 = Random.Range(3f, 6f);
         randomTimeDelay4 = Random.Range(3f, 6f);
         randomTimeDelay5 = Random.Range(3f, 6f);
         // Start calling the Spawn function repeatedly after a delay.
         InvokeRepeating("GenerateFirst", randomTimeDelay, 2.0f);
 
         if (Time.frameCount > (5 * 30))
         {
             InvokeRepeating("GenerateSecond", randomTimeDelay2, 2.0f);
             Debug.Log("2nd one coming to get you!");
 
             if (Time.frameCount > (20 * 30))
             {
                 InvokeRepeating("GenerateThird", randomTimeDelay3, 2.0f);
                 Debug.Log("3rd one coming to get you!");
 
                 if (Time.frameCount > (60 * 30))
                 {
                     InvokeRepeating("GenerateForth", randomTimeDelay4, 2.0f);
                     Debug.Log("4th one coming to get you!");
 
                     if (Time.frameCount > (90 * 30))
                     {
                         InvokeRepeating("GenerateFifth", randomTimeDelay5, 2.0f);
                         Debug.Log("5th one coming to get you!");
                     }
                 }
             } 
         }    
     }
 
     void GenerateFirst()
     {
         float randomX = Random.Range(-5.25f, 6.0f);
         newPositionL = new Vector2(randomX, 1.5f);
         newPositionC = new Vector2(randomX, 0.23f);
         Instantiate(cloud, newPositionC, Quaternion.identity);
         Instantiate(lightning, newPositionL, Quaternion.identity);
         Debug.Log("Spawned a kill object!");
     }
 
     void GenerateSecond()
     {
         float randomX1 = Random.Range(-5.25f, 6.0f);
         newPositionL1 = new Vector2(randomX1, 1.5f);
         newPositionC1 = new Vector2(randomX1, 0.23f);
         Instantiate(cloud, newPositionC1, Quaternion.identity);
         Instantiate(lightning, newPositionL1, Quaternion.identity);
     }
 
     void GenerateThird()
     {
         float randomX2 = Random.Range(-5.25f, 6.0f);
         newPositionL2 = new Vector2(randomX2, 1.5f);
         newPositionC2 = new Vector2(randomX2, 0.23f);
         Instantiate(cloud, newPositionC2, Quaternion.identity);
         Instantiate(lightning, newPositionL2, Quaternion.identity);
     }
 
     void GenerateForth()
     {
         float randomX3 = Random.Range(-5.25f, 6.0f);
         newPositionL3 = new Vector2(randomX3, 1.5f);
         newPositionC3 = new Vector2(randomX3, 0.23f);
         Instantiate(cloud, newPositionC3, Quaternion.identity);
         Instantiate(lightning, newPositionL3, Quaternion.identity);
     }
 
     void GenerateFifth()
     {
         float randomX4 = Random.Range(-5.25f, 6.0f);
         newPositionL4 = new Vector2(randomX4, 1.5f);
         newPositionC4 = new Vector2(randomX4, 0.23f);
         Instantiate(cloud, newPositionC4, Quaternion.identity);
         Instantiate(lightning, newPositionL4, Quaternion.identity);
     }
 
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

41 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

Related Questions

Instantiate spawn problem 1 Answer

Displaying C# Int Value to GUI 2 Answers

Having trouble increasing the spawning speed of explosions 0 Answers

Spawn a random object on more than one position 1 Answer

Clock doesn't stop when reaches 0.0. Can you help me with this. 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