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 glc · Aug 18, 2012 at 02:23 PM · objectdestroychangelevel

Change level after destroying all enemies?

Ok, I'm new in Unity3D and I've made some simple game where you are destroying cubes as enemies.. But now I need to change level after I destroy all cubes.

Do I need to add some variable to count cubes as objects? How to do it easiest way?

Thank you..

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 DavidD · Aug 18, 2012 at 03:59 PM

I don't know which language you're using so I'll go with C# because I am familiar with that.

You could either use a list or a simple variable. Whenever you add an enemy to the world you increment the variable (or add it to the list) and whenever the variable reaches 0 (or the list is empty) you change level. Of course you would also decrement the variable (or remove the enemies from the list) when they are destroyed.

You could put this script on either your main character or in some sort of "master object" if you have one of those. If not the main character will do fine.

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 glc · Aug 18, 2012 at 04:29 PM 0
Share

Ok, I use now javascript but I can handle C#.. I created array of objects but they don't desepear from list? Am I missing something? Can you write down few lines of code?

avatar image DavidD · Aug 18, 2012 at 05:34 PM 0
Share

At the beginning of your script which you attach to the main character you'd declare an int called "enemyAmount" or something like that and set it to 0.

Then if you add enemies through the editor, give them a tag like "enemy" and then you could do "enemyAmount = GameObject.FindGameObjectsWithTag("enemy").length" to get the amount of enemies (keep in $$anonymous$$d this is C# but you should get the gist)

Now, whenever the player kills an enemy you decrement enemyAmount by typing enemyAmount--. Then check if enemyAmount == 0, if so you change level.

Hope you understand that!

avatar image glc · Aug 19, 2012 at 05:20 PM 0
Share

Ok, I managed it :)

Here is code I used

pragma strict

var level:int;

function Start () {

}

function Update () { print(GameObject.FindGameObjectsWithTag("YOUR_TAG").Length);

if(GameObject.FindGameObjectsWithTag("YOUR_TAG").Length==0) {Application.LoadLevel(level);}

}

And I attached it to main characater..

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

9 People are following this question.

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

Related Questions

How to diappear a line renderer from start and end position of line 1 Answer

Can't proceed next level when the object destroy not complete. 2 Answers

A node in a childnode? 1 Answer

Destroy All of One One object on collision 1 Answer

fade object out? 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