• 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 zachseven · Jan 10, 2017 at 09:43 PM · enemyfallingworldscene-changefalling-through-floor

How can I have the enemies die when they fall through world?

I have a script where the scene goes to the next scene when all enemies have died.

using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;

public class Enemy : MonoBehaviour { // Number of enemies alive private static int aliveCounter = 14;

 void Start()
 {
     aliveCounter++;
 }

 void OnKilled()
 {
     aliveCounter--;

     if (aliveCounter == 0)
         SceneManager.LoadScene("Lv.02");
 }

}

But some of them don't die and fall through the game world which means the player can never advance. Rather that go on some massive collider hunt I'd rather just kill those enemies who fall through the world. Any idea what code I can attach to this script to make that happen?

Thanks!

Comment
Add comment · Show 2
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 ColouredCarnival · Jan 10, 2017 at 10:21 PM 0
Share

you could put a plane under your map which kills the enemies if they fall through and collide with the plane

avatar image zachseven ColouredCarnival · Jan 11, 2017 at 01:20 AM 0
Share

awesome thank you!

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GrayMatterTutorials · Jan 11, 2017 at 01:03 AM

If their transform.position.y < 0.0f, kill them! If it goes below the lowest point of the terrain, then they should die! You would have to check that in a FixedUpdate probably to save some memory, but it would kill them!

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 zachseven · Jan 11, 2017 at 01:22 AM 0
Share

Thank You!

avatar image
0

Answer by JoshBaz · Jan 11, 2017 at 01:27 AM

 public GameObject[] enemies;
 public float lowestY = -100f;
 
 void FixedUpdate(){
     for(int i =0; i < enemies.Length; i++){
         if(enemies[i].transform.position.y <= lowestY)
             //Finish him!
     }
 }
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 zachseven · Jan 11, 2017 at 01:45 AM 0
Share

Great! Thanks!

avatar image JoshBaz zachseven · Jan 12, 2017 at 05:17 PM 0
Share

No prob. If you think I my response answered your question could you please select it as the Correct Answer. 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

My object is falling through the platform 1 Answer

Prevent Fallthrough with Procedural Mesh and Collider 0 Answers

Use enemy as trigger just for the char ( not the ground ) 2 Answers

Checklist: Object or Character is falling through the floor 12 Answers

Crouching and falling through floor 0 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