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 ThatGUI52 · Aug 18, 2014 at 07:56 AM · instantiaterandomdelaysystemwave

Need help with random spawning system.

Ok, so im a new programmer, so my code is a little messy. but i will give you what i have completed. What I am hoping to accomplish is: 1. Create a wave spawn system with slight delay between spawns so enemy prefabs dont stack up and controlled wave delay between waves. 2. Randomize which empty game object (spawn point) is used to instantiate the prefabs. there will be four separate points. 3. Spawn specific enemies, not random, for each wave. So basically, i would have the ability to declare which enemy prefabs spawn on which waves with not pattern at all. (I understand this part will be time consuming.)

 using UnityEngine;
 using System.Collections;
 
 public class SpawnForWave : MonoBehaviour 
 {
 
     public int WaveCount = 1;
     private int EnemyCount = 0;
     private int Ammount2Spawn = 10;
     private GameObject SpawnPoints = GameObject.FindGameObjectWithTag("Spawn Point");
     public GameObject EnemyPref1;
     public GameObject EnemyPref2;
     public GameObject EnemyPref3;
     public GameObject EnemyPref4;
     
     
     void Update () 
     {
         if(WaveCount = 1)
         {
             for(int i = 0; i < Ammount2Spawn; i++)
             {
                 Instantiate(EnemyPref1, SpawnPoints.position, SpawnPoints.rotation);
                 Instantiate(EnemyPref2, SpawnPoints.position, SpawnPoints.rotation);
                 Instantiate(EnemyPref3, SpawnPoints.position, SpawnPoints.rotation);
                 Instantiate(EnemyPref4, SpawnPoints.position, SpawnPoints.rotation);
             }    
         }
     }
 }
 







Comment
Add comment · Show 1
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 Scribe · Aug 18, 2014 at 08:35 AM 0
Share

So umm... what's your problem? You need to ask a specific question, we are not here to simply write a script to your specification!

Don't know how to delay a wave spawn?

  • Search for wait on here

  • check out WaitForSeconds

  • Also see the page about coroutines

How to choose your spawn point?

  • Search lists or arrays on here.

  • Check out the Random class in the unity API, specifically Range

How to pick which enemies to spawn?

  • Personally I would set up a list of lists here (search for 2D array). Then your first index relates to which level it should be used by, and your second index is your prefab for the enemy you need to spawn.

  • Spawn them with a for loop, which you seem to know how to do!

Scribe

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by RedDevil · Aug 18, 2014 at 08:30 AM

I dont recomand using this for spawn points:

  private GameObject SpawnPoints = GameObject.FindGameObjectWithTag("Spawn Point");


If you do this then it will have to search for it everytime. Just declare it as public and add it in the inspector.

  1. Create a wave spawn system with slight delay between spawns so enemy prefabs dont stack up and controlled wave delay between waves. To do this you must create a new IEnumerator class and add wait for second calls like this: Just an example:

    IEnumerator example() { Instantiate(EnemyPref1, SpawnPoints.position, SpawnPoints.rotation); yield return new WaitForSeconds(Random.Range(1,5)); }

To call this function do it like this:

 StartCoroutine(example());

2.Randomize which empty game object (spawn point) is used to instantiate the prefabs. there will be four separate points. You can create a start a random number then asign with if statements for a value to spawn at a prefab.

3.Spawn specific enemies, not random, for each wave. So basically, i would have the ability to declare which enemy prefabs spawn on which waves with not pattern at all. (I understand this part will be time consuming.) You can just make a whole new function and with yields and timers spawn them just like that.

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 Scribe · Aug 18, 2014 at 08:49 AM 1
Share

nice answer +1 :)

GameObject.FindGameObjectWithTag("Spawn Point"); will only 'have to search for it everytime' if you put it in a repeating method like Update. If it is called in Start it should work fine without having to be called each time, though your alternative would work fine as well!

avatar image RedDevil · Aug 18, 2014 at 09:58 AM 0
Share

so puttin it there is the alternative of start. I see thank you i did not know that.

avatar image ThatGUI52 · Aug 24, 2014 at 03:48 AM 0
Share

Thanks. And sorry my question was so vague lol

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

When does Instantiate return ? 2 Answers

Spawn Random Enemy 3 Answers

instantiating vertically 2 Answers

How to Spawn multiple game object one by one in random order 1 Answer

Spawn GameObjects without overlap 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