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 UNKNOWN or whatever · Apr 03, 2011 at 07:22 AM · scenelevel

End level when all enemies eliminated

I am making a simple FPS and I want to transfer the player to the next level (scene) after all of the enemies are eliminated. How am I supposed to do this? I am a beginner to Unity, and I only understand a very basic Idea of scripting. Please tell me the script, and where, or how, to put it.

Thank You SO MUCH in advance!

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

2 Replies

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

Answer by Statement · Apr 03, 2011 at 11:53 AM

You could make use of a game controller to count the number of enemies in your scene by having them register with the controller when they enable and unregister when they disable. When you reach a count of 0, you can load a new level.

To do this, find or create an empty game object in your scene tagged GameController (by default, there is none).

On this game object with the tag GameController, add the following ObjectivesManager.

ObjectivesManager.js

private var objectives : int;

function OnEnableObjective() { objectives++; }

function OnDisableObjective() { objectives--; if (objectives == 0) SendMessage("OnObjectives"); }

function OnObjectives() { Application.LoadLevel(Application.loadedLevel + 1); }


Then, on every enemy you should have code like this. You want to let the controller know that an objective was enabled and disabled at key moments.

Objective.js

function OnEnable() { var gameController = GameObject.FindGameObjectWithTag("GameController"); gameController.SendMessage("OnEnableObjective"); }

function OnDisable() { var gameController = GameObject.FindGameObjectWithTag("GameController"); gameController.SendMessage("OnDisableObjective"); }

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 UNKNOWN or whatever · Apr 05, 2011 at 09:45 AM 0
Share

thanks statement, but it seems like it is not working. i think the script doesnt disable after the enemy dies

avatar image
1

Answer by Scribe · Apr 03, 2011 at 09:02 AM

function Update() { var enemies = GameObject.FindWithTag("enemy") //find gameobjects with the tag "enemy" (you must therefore tag the enemies with "enemy" if(enemies == null){ //if no gameobjects with the tag "enemy" are found

 //change scene

 }

}

not certain this will work as I'm away from unity at the moment but basically it finds all the gameobjects with the tag "enemy", if it doesn't find any then you can put in a script to change the scene

hopefully its useful

Scribe

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 ShinyTaco · Jun 24, 2013 at 11:57 AM 0
Share

This works great. Thanks!

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

How do I finish a level and send the player to the next? 3 Answers

Load a scene/level when enemy is close... 1 Answer

Random level select 1 Answer

The associated script cannot be loaded. 1 Answer

Can a script be loaded to a next scene? 3 Answers


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