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 user5200 · Jun 02, 2012 at 04:28 AM · c#spawningfindgameobjectswithtagenemy spawn

Spawner control and ending the level

Hi,

I am making a 2D game in which enemies will spawn throughout the level to attack the player. After a certain amount of enemies have been defeated, the spawner will stop spawning enemies and, after you kill the last remaining ones, the level should end.

I am having trouble with stopping the spawner and ending the level. I have recently fixed the spawner problem which was due to my carelessness. The more important question is how can I detect whether or not the scene contains enemies?

Here are 2 variations of the LevelisClear() check that I have tried:

 public bool levelIsClear()
     {
         if (GameObject.FindGameObjectsWithTag("Enemy") == null &&
             GameObject.FindGameObjectsWithTag("Ground") == null &&
             GameObject.FindGameObjectsWithTag("Hardcore") == null)
             return true;
         else return false;
     }

 public bool levelIsClear()
     {
         if (GameObject.Find("Enemy1(Clone)") == null &&
             GameObject.Find("Groundguy(Clone)") == null &&
             GameObject.Find("Hardcore(Clone)") == null)
             return true;
         else return false;
     }

I'm not sure about these as they contain Unity exclusive functions that I don't have much experience with. Am I using them correctly? Or is there a better way to check for enemy presence on screen?

Comment
Add comment · Show 5
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 pborg · Jun 02, 2012 at 04:41 AM 0
Share

it would seem that all your logic is in tact but I can't look to see if your notation is correct from here. In your code example here, the $$anonymous$$axEnemies isn't set to an integer. your second set of code should be in the update function if it's not already.

avatar image user5200 · Jun 02, 2012 at 05:24 AM 0
Share

Sorry, I usually set $$anonymous$$axEnemies from within unity so I can increase or decrease the amount as I please. Right now, it is set to 20. The second set is also in update, in fact, it is right below the first set.

avatar image whydoidoit · Jun 02, 2012 at 09:31 AM 0
Share

Are you sure that is your only spawning code? Perhaps you could post the rest of your Update function and one of the Spawn routines?

avatar image whydoidoit · Jun 02, 2012 at 09:14 PM 0
Share

And I know you imply you don't, but to confirm, enemyCount isn't decremented or returned to 0 somewhere?

avatar image user5200 · Jun 06, 2012 at 08:20 PM 0
Share

Sorry for all the confusion, I discovered that there was a ghost spawner that was a child of some random object in the scene. I must have accidentally dragged him there and forgot.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Instantiating at different rates 1 Answer

Multiple Cars not working 1 Answer

How to make objects appear with mouse click in a row? 2 Answers

When spawning to a grid, how to only spawn one object next to another? 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