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 ProjectCryken · Feb 17, 2013 at 09:10 PM · javascriptspawnspawnpoints

Semi - Advanced Spawn System

Ok, so I have a plan for a spawn system, yet I have no idea how to create it. I have many 'Spawn points' placed around my world that I want to spawn my enemies. Each round of my game will have a set no. of enemies to spawn in over that round(this no. will increase every round to increase difficulty) however I need to limit the amount that can be alive at any given time(performance) to a set number.

EG. 40 enemies must spawn in over the round, however only 10 can be alive at any given point, so every time the enemy count drops below 10 another will spawn in until 40 zombies have been spawned. (These numbers are just examples)

Also, the spawn point chosen for each spawn must be random and obviously 2 or more enemies cannot spawn on the same spawn point at once. If somebody could put together a script to do this I'd really appreciate it, as I have no idea where to start.

Javascript only please!

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 tavoevoe · Feb 17, 2013 at 09:46 PM

 var zombie:GameObject; //Set the zombie model in the inspector
 var maxZombies:int; //set max zombies in this round
 var maxLiveZombies:int; //set max zombies alive at once
 private var zombiesThisRound:int = 0; //this is the number of zombies that have spawned this round, alive or dead
 private var previousSpawnPoint:GameObject; //this is where the last zombie spawned
 
 void Start()
 {
      previousSpawnPoint = GameObject.FindGameObjectsWithTag("spawnpoints")[0]; //this will break if you have no spawnpoints tagged "spawnpoints".
 }
 
 void Update()
 {
      while(GameObject.FindGameObjectsWithTag("zombie").length < maxLiveZombies:int || zombiesThisRound > maxZombies) //while zombies need to spawn because there aren't enough on the map and enough zombies haven't spawned yet.
      {
           var spawnPoints = GameObject.FindGameObjectsWithTag("spawnpoints"); //get a list of all spawn points
           var spawnPoint = previousSpawnPoint; //choose a default spawn point
           while(spawnPoint == previousSpawnPoint && spawnPoints.length > 1) //keep choosing a random spawn point until you choose one you haven't choosen yet
           {
                var spawnPoint = spawnPoints[Math.floor(Math.random() * spawnPoints.length)];
           }
           previousSpawnPoint = spawnPoint; //store where the zombie spawn last
           var newZombie = Instantiate(zombie, spawnPoint.transform.position, spawnPoint.transform.rotation); //create the new zombie
           newZombie.tag = "zombie"; //tag it as a zombie
           zombiesThisRound++; //increase the number of spawned zombies.
      }
      
 }

I don't know if this will work. It's close to functional, though. I wrote the whole thing in the browser. Consider it a learning experience getting it to function.

Comment
Add comment · Show 1 · 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 ProjectCryken · Feb 17, 2013 at 11:15 PM 0
Share

Hey man! Cant thankyou enough, worked great after a few tweaks.

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

10 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

Related Questions

Spawning enemies in waves 1 Answer

How do I create a spawn point 2 Answers

Enemy spawn 1 Answer

Spawn player to a different scene 0 Answers

varibals coincidence 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