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 Davidflynn · Dec 05, 2011 at 05:35 PM ·

Win game based on destroying enemys

I am building an airplain game where you fly around the city destroying tanks and other airplains to win the game. My question is how would i go about making a script that once I destroy all three tanks/plains, it go to game over. All my enemy are tagged enemy. I really dont have any starting code because im not sure how to start this one.

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

Answer by FLASHDENMARK · Dec 05, 2011 at 06:27 PM

This assumes you know exactly how many enemies there will be in a given scene.

  • First create a script call it "GameWinner"(bad name, I know)

  • In the script you write this:

       static var destroyedEnemies = 0; //Current number of destroyed enemys
         
         var numberOfEnemies : int; //Fill this in the Inspector.
     
         function Update (){
     
     if(destroyedEnemies >= numberOfEnemies){
     
             //End the game here.
             }
         }
    
  • When you destroy/kill your enemies you write:

    GameWinner.destroyedEnemies++; // This adds to the variable "destroyedEnemies" in the "GameWinner" script.

I hope this helps, please tell if you need some help or clarification. I'll be happy to help.

P.S I am sorry for the poorly formatted code, it would(for some reason) not format it properly.

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 Davidflynn · Dec 05, 2011 at 08:09 PM 0
Share

For some reson this is playing end game instantly on play. I placed this on my tank >

GameWinner.destroyedEnemies++;

I have set it to is trigger.

I have this on my plain.

static var destroyedEnemies = 0; //Current number of destroyed enemys

var numberOfEnemies : int; //Fill this in the Inspector.

function Update (){

if(destroyedEnemies >= numberOfEnemies){

 Application.LoadLevel("End Game");

 }

}

avatar image
0

Answer by cj_coimbra · Dec 05, 2011 at 06:21 PM

You could have an empty gameobject with a script just to check the game over conditions. You could mantain a variable in this script with the maximum number of enemies for your level. Whenever you create an enemy, you subtract one from that variable. Whenever one of the active enemies are destroyed check if that variable is greater than zero. If not, you can load another scene with a proper game over GUI or just enable some overlaying GUI on that same scene.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Rest postion after animation plays 0 Answers

Spawning portal 1 Answer

Making a Jetpack 3 Answers

Convert JS to C# 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