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 /
avatar image
1
Question by dreal · Apr 04, 2010 at 09:26 AM · gameobjectinstantiatecharacterdestroyrenderer

Destroying all enemy characters after the level is over

Hey, I'm trying to stop instantiating my enemy character when the level ends which last for 4 seconds then goes to the next stage. I don't want enemies to still be attacking when the level is done. Any Help?

Thanks alot, But how would i destroy the ramaining zombies that have already spawned after the instantiate function is shut off??

var wakeUpZombie : GameObject; var wakeUpZombie1 : GameObject;

var wakeUpZombie3 : GameObject; var wakeUpZombie4 : GameObject; var wakeUpOldZombie1 : GameObject; var wakeUpOldZombie2 : GameObject; //var wakeUpOldZombie3 : GameObject; var stopZombies : EnemyAI;

function Start() {

reSpawn(); reSpawn2(); reSpawn3(); reSpawn4(); reSpawnOldZombie1(); reSpawnOldZombie2(); //reSpawnOldZombie3(); }

//This is for My Zombie.... function reSpawn(){ while(true){ yield new WaitForSeconds(15); wakeUpZombie.Instantiate(wakeUpZombie); if(stopZombies.count == 13){ Destroy(wakeUpZombie); } } }

function reSpawn2(){ while(true){ yield new WaitForSeconds(50); wakeUpZombie.Instantiate(wakeUpZombie1);

if(stopZombies.count == 13){ Destroy(wakeUpZombie1); } } }

function reSpawn3(){ while(true){ yield new WaitForSeconds(15); wakeUpZombie.Instantiate(wakeUpZombie3);

if(stopZombies.count == 13){ Destroy(wakeUpZombie3); } } }

function reSpawn4(){ while(true){ yield new WaitForSeconds(30); wakeUpZombie.Instantiate(wakeUpZombie4);

if(stopZombies.count == 13){ Destroy(wakeUpZombie4); } } }

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 Not showing my name · Apr 22, 2010 at 05:30 PM 0
Share

how about making the level end when they all die?

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by duck · Apr 04, 2010 at 04:18 PM

I think what you probably need to do here is to have a boolean variable which determines whether the game is within the 4-second "finishing" state.

Then, you could replace all your

while(true)

statements, with

while(!finishing)

(the ! means "not")

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
1
Best Answer

Answer by Eric5h5 · Apr 04, 2010 at 08:58 PM

Considering that your code is doing the same thing over and over with just a couple of minor variations, it would be far shorter and easier to manage if you use an array and a function that takes a couple of parameters:

var wakeUpZombie : GameObject[];

function Start() { Respawn(0, 15); Respawn(1, 50); Respawn(2, 15); Respawn(3, 30); }

function Respawn (zombieNumber : int, delay : float) { while (true) { yield WaitForSeconds(delay); if (EnemyAI.count < 13) { Instantiate(wakeUpZombie[zombieNumber]); } } }

function LevelEnd () { StopAllCoroutines(); }

You can call the LevelEnd function from somewhere when the level ends, and that will make all the Respawn functions stop.

Comment
Add comment · Show 2 · 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 dreal · Apr 05, 2010 at 02:34 AM 0
Share

Thanks alot, But how would i destroy the ramaining zombies that have already spawned after the instantiate function is shut off??

avatar image Eric5h5 · Apr 05, 2010 at 04:34 AM 0
Share

@dreal: easiest way is to give them all a tag, called "Zombie" I guess, then do var zombies = GameObject.FindGameObjectsWithTag("Zombie"); for (zombie in zombies) Destroy (zombie);

avatar image
0

Answer by Peter G · Apr 04, 2010 at 08:14 PM

I think when the level finishes you should have a BroadcastMessage that disables the zombie spawner.

Comment
Add comment · Show 2 · 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 Not showing my name · Apr 22, 2010 at 05:34 PM 0
Share

ah now THAT'S and idea.

avatar image geacksnagueld · Aug 19, 2020 at 08:30 AM 0
Share

Thanks for Giving us Such a Great Information telldunkin

avatar image
0

Answer by Llama_w_2Ls · Aug 19, 2020 at 08:41 AM

Well in your spawner you could parent all zombies, when theyre instantiated, to an empty GO, then, when the level is complete, run some code to destroy all GOs inside that empty. For example:

 void DestroyAllEnemies()
 {
      foreach(Transform child in EmptyParentGO)
      {
           Destroy(child.gameObject);
      }
 }

(Assuming that all enemies are children of the gameobject EmptyParentGO)

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

1 Person is following this question.

avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Replacing object: first object not completely destroyed? 0 Answers

PlayerRespawn class wont Instantiate the player prefab 1 Answer

Replace GameObject vs. replacing mesh and material? 2 Answers

Destroy and rebuild game objects from lists 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