Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MisterFox · Oct 24, 2017 at 10:55 PM · destroyparentchildchildrenparenting

Destroy one child (of same instance) after another?

Hey, so the way my game works right now is that due to a certain event, a bunch of "Point"-objects spawn, and they instantly attach themselves to a "Target"-object as children.

The Target has a constant timer running down, and every x seconds, it should destroy one of the Points-Children attached to it - only one at a time though! And it doesn't matter which one. Once one is destroyed, the Timer resets, and only when x seconds have passed again, it should destroy another Point-Child - until none are left.

What I thought I could do in Unity is have the Target run through its own list of children, and as soon as it finds one Point-object in its Child-list, it would destroy that and reset the timer. I'm not sure how to do that though, or if it's the best solution, so any help and ideas are appreciated!

Thank you very much!

Comment
Add comment · Show 1
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 Hatsuko · Oct 26, 2017 at 01:02 PM 0
Share

Haha again I'm not sure which part you need help. It all sounds reasonable to me so far. So I'll just write whatever things that comes to my $$anonymous$$d and hope it doesn't sounds dumb.

Create a List of "Point". Cache all "Point" children on Start().

 private List<Point> pointList = new List<Point>();
 
 void Start () {
     // Here you cache all "Point"
     // You'll need
     // https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html
     // https://unity3d.com/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries
 }

And the Timer thing just google "Unity Timer".

When time arrives, you need to Destroy() a "Point". You said "it doesn't matter which one" so you'll need to pick a random one from the List. $$anonymous$$aybe you need to generate a random index and use it to pick from List. Then reset the timer.

Finally, you said "due to a certain event"... it depends on how you want to do it. $$anonymous$$aybe you need this or maybe not. But you'll need to move the "Point" cacheing part from Start() to another function, say "OnPointSpawn()". So when that event happens you call OnPointSpawn().

0 Replies

· Add your reply
  • Sort: 

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

121 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 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 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 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 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 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 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 avatar image avatar image

Related Questions

Make Parent Follow Child and Vice Versa? 1 Answer

Destroyng all childs of an object 1 Answer

destroy other child objects when the parent counts more than 1 child 1 Answer

Why can't I access the public variables of the children class of TestItem in this syntax? I only have access to TestItem variables 1 Answer

How to destroy child of GameObject? 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