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 Tekksin · Nov 06, 2013 at 11:22 PM · triggerenemychildrenkill

A trigger to kill all parts of an enemy?

This is a general question, but I have multiple box collisions and triggers on my enemies in my game. My character has a power up that makes her kill anything she touches, but sometimes not ALL of the parts of the enemy are taken out (such as the moving script or others{I have enemies you can bounce on and stuff}).

I was wondering if there was a way for me to just make a trigger and say, "EVERYTHING that is a child of this.... if the player has the powerup and hits this trigger... kill everything... KILL ALL THE CHILDREN!!"

....is there a script that allows me to kill all the children? If you need more information from me, let me know and I'll tell you more things in depth. Thanks a lot for your help!

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 Starwalker · Nov 06, 2013 at 11:32 PM 0
Share

Do you have an array or list type container where you are storing the number's of instances of Enemy "GameObjects" ?

avatar image Tekksin · Nov 06, 2013 at 11:38 PM 0
Share

no, im unsure how to use arrays. I just have some in empty game objects, and others contained under the graphics part of the enemy. It's dependent on what kind of enemy it is, and what needs to allow the player to survive, when touched. So everything is set up as a parent with children, to keep the prefabs working. Nothing is done through an array, mostly because, again, I have no experience with that kind of thing.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Crazydadz · Nov 06, 2013 at 11:30 PM

Do some search before posting question. They are a lot of way to destroy childrens. One of multiple answer

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 Tekksin · Nov 06, 2013 at 11:31 PM 0
Share

I need it in java, though. That's C#

avatar image Crazydadz · Nov 06, 2013 at 11:36 PM 0
Share

be more specific in your question though...Find a way to transpose it, its easy though. $$anonymous$$arkD did it! You are lucky.

avatar image
0

Answer by MarkD · Nov 06, 2013 at 11:33 PM

Well, if you want the colliders to be 'gone' from the game world and never come back, you already gave your answers yourself you simply search all the children and destroy them.

 var parent:Transform;
 
 Java
 
 for (var:Child in parent){
 Destroy(Child.gameObject);
 }
 
 
  
 C#
 
 Transform parent;
 
 foreach(Transform child in parent) {
 
     Destroy(Child.gameObject);
 
 }


Now note that this is made on the fly and has not been tested, but it gives you a general starting point to go from.

Now if you want only to delete the scripts of the enemy but keeps all its GameObjects alive in the game you should take a look at this http://docs.unity3d.com/Documentation/ScriptReference/Component.GetComponentsInChildren.html

Comment
Add comment · Show 4 · 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 Tekksin · Nov 06, 2013 at 11:34 PM 0
Share

thanks a lot! I will toy with that in a bit. I wasn't familiar with the child.gamObject script so i didn't know how to search for solutions. It's been driving me nuts! lol. thanks.

avatar image Tekksin · Nov 06, 2013 at 11:50 PM 0
Share

am i allowed to attach a script like this to an empty game object or is that nonsensical?

avatar image Tekksin · Nov 07, 2013 at 02:56 PM 0
Share

I'm not getting anything out of your suggestion. it's not working for me. Unity doesn't know what child is..

avatar image MarkD · Nov 07, 2013 at 08:21 PM 0
Share

you have to refer the transform wich contains the childs in the transfrom slot, Unity ofcourse does not know what a child is if it does not get a parent :). and you can atach the script to an empty object, but for that you need to tweak it, toy arround. As I mentioned this script is just a point in the right direction, it is not tested and for that reason might not even work.

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

17 People are following this question.

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

Related Questions

Kill enemy when animation is playing 1 Answer

How could i access to a specific collider box if it is in a children of the main Object? The script is in the main object. 1 Answer

Disable a target after trigger exit? 1 Answer

If Enemy Health (< 10) then Exp (+10)? 1 Answer

Need help for programming the killing of an enemy 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