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
1
Question by mido555 · Dec 29, 2010 at 06:03 PM · enemyspawnlimit

Spawn Limit for enemies

Can someone please give me a script that will limit the enemies being spawned to 50 so i will have 50 enemies on my screen and if i have 49 then one will spawn. I already have a script that spawns enemies i only need a script that kills them and limits them to only 50 on 1 screen.

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
2

Answer by s4vi0r · Dec 29, 2010 at 07:13 PM

(=

All you really have to do is in your enemy script when you make then enemy die based on health or whatever spawn another.

Update() { if(health <= 0) { enemycount--; SpawnNewEnemy(); Destroy(this.gameObject); enemycount++; }

}

If you want to limit to 50 and you are managing them all from 1 script then you might want to either have a counter or store them in an array. Keep it under 50 by checking the size vs 50.

I would do it via array for management purposes.

var enemies : Array; var enemyPrefab : GameObject;

function Start() { enemies = new Array(); } function SpawnNewEnemy() { if(enemies.length >= 50) { return; }

var newEnemy = Instantiate(enemyPrefab, Vector3(0,0,0), Quaternion.identity); enemies.Add(newEnemy);

}

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 mido555 · Dec 29, 2010 at 08:54 PM 1
Share

Thats helpful, but not in my case, I need something that wont let more then 50 spawn but what your script does is if one dies then another one will be born i only want something that will only spawn 50 enemies. Sorry if this is annoying but i have to do finish this because christmas holiday is almost over and i will have LOTS of tests so i need to finish everthing this week or wait a month and i want to submit my project to a contest. Oh and something to help you, my enemy and my player share the same script

avatar image s4vi0r · Dec 29, 2010 at 09:18 PM 1
Share

I edited my post hope this is better for you.

avatar image mido555 · Dec 29, 2010 at 10:19 PM 1
Share

YAY this is alot better thanks alot :DDDDD

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

No one has followed this question yet.

Related Questions

Tower Defence style spawning(enemies) 1 Answer

Spaceshooter enemy spawning problem 1 Answer

Enemies Spawn, Then Follow Waypoints 1 Answer

Spawning different enemies for different levels 1 Answer

No appropriate version of 'UnityEngine.Object.Instantiate' 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